[ovs-dev] [PATCH] ofproto: Fix sparse warnings about treating ofp_port_t as integer.

Gurucharan Shetty shettyg at nicira.com
Fri Aug 23 17:40:50 UTC 2013


On Thu, Aug 22, 2013 at 11:19 AM, Ben Pfaff <blp at nicira.com> wrote:

> Fixes the following sparse warnings introduced by commit 7c35397c84d
> (ofproto: Start ofport allocation from the previous max after restart.)
>
> ofproto.c:2106:58: warning: restricted ofp_port_t degrades to integer
> ofproto.c:2107:40: warning: restricted ofp_port_t degrades to integer
> ofproto.c:2107:40: warning: restricted ofp_port_t degrades to integer
> ofproto.c:2107:38: warning: incorrect type in assignment (different base
> types)
> ofproto.c:2107:38:    expected restricted ofp_port_t [usertype]
> alloc_port_no
> ofproto.c:2107:38:    got int
>
> This fix makes the code uglier.  Maybe we should make 'alloc_port_no'
> and 'max_ports' "uint16_t"s instead of "ofp_port_t"s.
>
Sparse 0.4.3 did not show this warning to me (it comes in ubuntu 12.04). I
had to compile the sparse master branch for this to work for me. Sorry
about that.


>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
>  ofproto/ofproto.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
> index 947b8c6..468e08e 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -2103,9 +2103,11 @@ init_ports(struct ofproto *p)
>              netdev = ofport_open(p, &ofproto_port, &pp);
>              if (netdev) {
>                  ofport_install(p, netdev, &pp);
> -                if (ofproto_port.ofp_port < p->max_ports) {
> -                    p->alloc_port_no = MAX(p->alloc_port_no,
> -                                           ofproto_port.ofp_port);
> +                if (ofp_to_u16(ofproto_port.ofp_port)
> +                    < ofp_to_u16(p->max_ports)) {
> +                    p->alloc_port_no = u16_to_ofp(
> +                        MAX(ofp_to_u16(p->alloc_port_no),
> +                            ofp_to_u16(ofproto_port.ofp_port)));
>                  }
>              }
>          }
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130823/479bbde7/attachment-0003.html>


More information about the dev mailing list