* [PATCH] net: avoid uninitialized variable
@ 2016-10-27 3:56 zhongjiang
2016-10-27 4:02 ` Gao Feng
0 siblings, 1 reply; 3+ messages in thread
From: zhongjiang @ 2016-10-27 3:56 UTC (permalink / raw)
To: davem, aduyck, tom, jiri, fgao, hadarh, amir; +Cc: netdev, linux-kernel
From: zhong jiang <zhongjiang@huawei.com>
when I compiler the newest kernel, I hit the following error with
Werror=may-uninitalized.
net/core/flow_dissector.c: In function ?._skb_flow_dissect?
include/uapi/linux/swab.h:100:46: error: ?.lan?.may be used uninitialized in this function [-Werror=maybe-uninitialized]
net/core/flow_dissector.c:248:26: note: ?.lan?.was declared here
This adds an additional check for proto to explicitly tell the compiler
that vlan pointer have the correct value before it is used.
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
net/core/flow_dissector.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 1a7b80f..a04d9cf 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -245,7 +245,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
}
case htons(ETH_P_8021AD):
case htons(ETH_P_8021Q): {
- const struct vlan_hdr *vlan;
+ const struct vlan_hdr *vlan = NULL;
if (skb_vlan_tag_present(skb))
proto = skb->protocol;
@@ -276,7 +276,8 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
key_vlan->vlan_priority =
(skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT);
- } else {
+ } else if (proto == cpu_to_be16(ETH_P_8021Q) ||
+ proto == cpu_to_be16(ETH_P_8021AD)) {
key_vlan->vlan_id = ntohs(vlan->h_vlan_TCI) &
VLAN_VID_MASK;
key_vlan->vlan_priority =
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: avoid uninitialized variable
2016-10-27 3:56 [PATCH] net: avoid uninitialized variable zhongjiang
@ 2016-10-27 4:02 ` Gao Feng
2016-10-27 5:53 ` zhong jiang
0 siblings, 1 reply; 3+ messages in thread
From: Gao Feng @ 2016-10-27 4:02 UTC (permalink / raw)
To: zhongjiang
Cc: David S. Miller, Alex Duyck, Tom Herbert, jiri, hadarh, amir,
Linux Kernel Network Developers, linux-kernel
On Thu, Oct 27, 2016 at 11:56 AM, zhongjiang <zhongjiang@huawei.com> wrote:
> From: zhong jiang <zhongjiang@huawei.com>
>
> when I compiler the newest kernel, I hit the following error with
> Werror=may-uninitalized.
>
> net/core/flow_dissector.c: In function ?._skb_flow_dissect?
> include/uapi/linux/swab.h:100:46: error: ?.lan?.may be used uninitialized in this function [-Werror=maybe-uninitialized]
> net/core/flow_dissector.c:248:26: note: ?.lan?.was declared here
>
> This adds an additional check for proto to explicitly tell the compiler
> that vlan pointer have the correct value before it is used.
>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
> net/core/flow_dissector.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
> index 1a7b80f..a04d9cf 100644
> --- a/net/core/flow_dissector.c
> +++ b/net/core/flow_dissector.c
> @@ -245,7 +245,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
> }
> case htons(ETH_P_8021AD):
> case htons(ETH_P_8021Q): {
> - const struct vlan_hdr *vlan;
> + const struct vlan_hdr *vlan = NULL;
>
> if (skb_vlan_tag_present(skb))
> proto = skb->protocol;
> @@ -276,7 +276,8 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
> key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
> key_vlan->vlan_priority =
> (skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT);
> - } else {
> + } else if (proto == cpu_to_be16(ETH_P_8021Q) ||
> + proto == cpu_to_be16(ETH_P_8021AD)) {
> key_vlan->vlan_id = ntohs(vlan->h_vlan_TCI) &
> VLAN_VID_MASK;
> key_vlan->vlan_priority =
> --
> 1.8.3.1
>
It seems there is one similar patch already.
You could refer to https://patchwork.kernel.org/patch/9389565/
Regards
Feng
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: avoid uninitialized variable
2016-10-27 4:02 ` Gao Feng
@ 2016-10-27 5:53 ` zhong jiang
0 siblings, 0 replies; 3+ messages in thread
From: zhong jiang @ 2016-10-27 5:53 UTC (permalink / raw)
To: Gao Feng
Cc: David S. Miller, Alex Duyck, Tom Herbert, jiri, hadarh, amir,
Linux Kernel Network Developers, linux-kernel
On 2016/10/27 12:02, Gao Feng wrote:
> On Thu, Oct 27, 2016 at 11:56 AM, zhongjiang <zhongjiang@huawei.com> wrote:
>> From: zhong jiang <zhongjiang@huawei.com>
>>
>> when I compiler the newest kernel, I hit the following error with
>> Werror=may-uninitalized.
>>
>> net/core/flow_dissector.c: In function ?._skb_flow_dissect?
>> include/uapi/linux/swab.h:100:46: error: ?.lan?.may be used uninitialized in this function [-Werror=maybe-uninitialized]
>> net/core/flow_dissector.c:248:26: note: ?.lan?.was declared here
>>
>> This adds an additional check for proto to explicitly tell the compiler
>> that vlan pointer have the correct value before it is used.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>> net/core/flow_dissector.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
>> index 1a7b80f..a04d9cf 100644
>> --- a/net/core/flow_dissector.c
>> +++ b/net/core/flow_dissector.c
>> @@ -245,7 +245,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
>> }
>> case htons(ETH_P_8021AD):
>> case htons(ETH_P_8021Q): {
>> - const struct vlan_hdr *vlan;
>> + const struct vlan_hdr *vlan = NULL;
>>
>> if (skb_vlan_tag_present(skb))
>> proto = skb->protocol;
>> @@ -276,7 +276,8 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
>> key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
>> key_vlan->vlan_priority =
>> (skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT);
>> - } else {
>> + } else if (proto == cpu_to_be16(ETH_P_8021Q) ||
>> + proto == cpu_to_be16(ETH_P_8021AD)) {
>> key_vlan->vlan_id = ntohs(vlan->h_vlan_TCI) &
>> VLAN_VID_MASK;
>> key_vlan->vlan_priority =
>> --
>> 1.8.3.1
>>
> It seems there is one similar patch already.
> You could refer to https://patchwork.kernel.org/patch/9389565/
>
> Regards
> Feng
>
> .
>
sorry, I doesn't notice that patch.
Thanks
zhongjiang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-27 5:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-27 3:56 [PATCH] net: avoid uninitialized variable zhongjiang
2016-10-27 4:02 ` Gao Feng
2016-10-27 5:53 ` zhong jiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.