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

Alex Wang alexw at nicira.com
Thu Aug 22 21:04:22 UTC 2013


I send out two patches to refine it.

http://openvswitch.org/pipermail/dev/2013-August/031017.html

http://openvswitch.org/pipermail/dev/2013-August/031018.html


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

> Yes, please give it a try.
> On Aug 22, 2013 11:30 AM, "Alex Wang" <alexw at nicira.com> wrote:
>
>> Can I have a try and see how cleaner it would be if we use "uint16_t"?
>>
>>
>> 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.
>>>
>>> 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/20130822/be520232/attachment-0003.html>


More information about the dev mailing list