* [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb
@ 2017-10-30 22:47 Gustavo A. R. Silva
2017-10-30 23:33 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-30 22:47 UTC (permalink / raw)
To: Dmitry Tarnyagin, David S. Miller
Cc: netdev, linux-kernel, Gustavo A. R. Silva
container_of is never null, so this null check is unnecessary.
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
net/caif/chnl_net.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index 922ac1d..489298d 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
u8 buf;
priv = container_of(layr, struct chnl_net, chnl);
- if (!priv)
- return -EINVAL;
skb = (struct sk_buff *) cfpkt_tonative(pkt);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb
2017-10-30 22:47 [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb Gustavo A. R. Silva
@ 2017-10-30 23:33 ` Gustavo A. R. Silva
2017-10-31 2:33 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-30 23:33 UTC (permalink / raw)
To: Dmitry Tarnyagin, David S. Miller; +Cc: netdev, linux-kernel
Hi,
Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
> container_of is never null, so this null check is unnecessary.
>
> This code was detected with the help of Coccinelle.
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
> net/caif/chnl_net.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
> index 922ac1d..489298d 100644
> --- a/net/caif/chnl_net.c
> +++ b/net/caif/chnl_net.c
> @@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,
> struct cfpkt *pkt)
> u8 buf;
>
> priv = container_of(layr, struct chnl_net, chnl);
> - if (!priv)
> - return -EINVAL;
>
> skb = (struct sk_buff *) cfpkt_tonative(pkt);
>
> --
> 2.7.4
Please, ignore this patch.
I just realized that function chnl_recv_cb is being called only during
initialization:
chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() ->
chnl_recv_cb():
static void ipcaif_net_setup(struct net_device *dev)
{
[...]
priv = netdev_priv(dev);
priv->chnl.receive = chnl_recv_cb;
[...]
}
static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
.kind = "caif",
.priv_size = sizeof(struct chnl_net),
.setup = ipcaif_net_setup,
.maxtype = IFLA_CAIF_MAX,
.policy = ipcaif_policy,
.newlink = ipcaif_newlink,
.changelink = ipcaif_changelink,
.get_size = ipcaif_get_size,
.fill_info = ipcaif_fill_info,
};
static int __init chnl_init_module(void)
{
return rtnl_link_register(&ipcaif_link_ops);
}
Thanks
--
Gustavo A. R. Silva
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb
2017-10-30 23:33 ` Gustavo A. R. Silva
@ 2017-10-31 2:33 ` Gustavo A. R. Silva
2017-10-31 4:12 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-31 2:33 UTC (permalink / raw)
To: Dmitry Tarnyagin, David S. Miller; +Cc: netdev, linux-kernel
Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
> Hi,
>
> Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
>
>> container_of is never null, so this null check is unnecessary.
>>
>> This code was detected with the help of Coccinelle.
>>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>> net/caif/chnl_net.c | 2 --
>> 1 file changed, 2 deletions(-)
>>
>> diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
>> index 922ac1d..489298d 100644
>> --- a/net/caif/chnl_net.c
>> +++ b/net/caif/chnl_net.c
>> @@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,
>> struct cfpkt *pkt)
>> u8 buf;
>>
>> priv = container_of(layr, struct chnl_net, chnl);
>> - if (!priv)
>> - return -EINVAL;
>>
>> skb = (struct sk_buff *) cfpkt_tonative(pkt);
>>
>> --
>> 2.7.4
>
> Please, ignore this patch.
>
> I just realized that function chnl_recv_cb is being called only
> during initialization:
>
> chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() ->
> chnl_recv_cb():
>
Well, here ipcaif_net_setup stores a pointer to chnl_recv_cb in a
structure. It doesn't call it.
> static void ipcaif_net_setup(struct net_device *dev)
> {
> [...]
> priv = netdev_priv(dev);
> priv->chnl.receive = chnl_recv_cb;
>
> [...]
> }
>
> static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
> .kind = "caif",
> .priv_size = sizeof(struct chnl_net),
> .setup = ipcaif_net_setup,
> .maxtype = IFLA_CAIF_MAX,
> .policy = ipcaif_policy,
> .newlink = ipcaif_newlink,
> .changelink = ipcaif_changelink,
> .get_size = ipcaif_get_size,
> .fill_info = ipcaif_fill_info,
>
> };
>
> static int __init chnl_init_module(void)
> {
> return rtnl_link_register(&ipcaif_link_ops);
> }
>
--
Gustavo A. R. Silva
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb
2017-10-31 2:33 ` Gustavo A. R. Silva
@ 2017-10-31 4:12 ` Gustavo A. R. Silva
0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-31 4:12 UTC (permalink / raw)
To: Dmitry Tarnyagin, David S. Miller; +Cc: netdev, linux-kernel
Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
> Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
>
>> Hi,
>>
>> Quoting "Gustavo A. R. Silva" <garsilva@embeddedor.com>:
>>
>>> container_of is never null, so this null check is unnecessary.
>>>
>>> This code was detected with the help of Coccinelle.
>>>
>>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>>> ---
>>> net/caif/chnl_net.c | 2 --
>>> 1 file changed, 2 deletions(-)
>>>
>>> diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
>>> index 922ac1d..489298d 100644
>>> --- a/net/caif/chnl_net.c
>>> +++ b/net/caif/chnl_net.c
>>> @@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,
>>> struct cfpkt *pkt)
>>> u8 buf;
>>>
>>> priv = container_of(layr, struct chnl_net, chnl);
>>> - if (!priv)
>>> - return -EINVAL;
But the driver only passes in to container_of the type of driver
structure registered with it. So this type of manipulation must be
completely safe. Right?
Now it seems to me (again) that the patch is fine.
I'm sorry, I'm a little bit confused here.
>>>
>>> skb = (struct sk_buff *) cfpkt_tonative(pkt);
>>>
>>> --
>>> 2.7.4
>>
>> Please, ignore this patch.
>>
>> I just realized that function chnl_recv_cb is being called only
>> during initialization:
>>
>> chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() ->
>> chnl_recv_cb():
>>
>
> Well, here ipcaif_net_setup stores a pointer to chnl_recv_cb in a
> structure. It doesn't call it.
>
>> static void ipcaif_net_setup(struct net_device *dev)
>> {
>> [...]
>> priv = netdev_priv(dev);
>> priv->chnl.receive = chnl_recv_cb;
>>
>> [...]
>> }
>>
>> static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
>> .kind = "caif",
>> .priv_size = sizeof(struct chnl_net),
>> .setup = ipcaif_net_setup,
>> .maxtype = IFLA_CAIF_MAX,
>> .policy = ipcaif_policy,
>> .newlink = ipcaif_newlink,
>> .changelink = ipcaif_changelink,
>> .get_size = ipcaif_get_size,
>> .fill_info = ipcaif_fill_info,
>>
>> };
>>
>> static int __init chnl_init_module(void)
>> {
>> return rtnl_link_register(&ipcaif_link_ops);
>> }
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-31 4:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-30 22:47 [PATCH] net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb Gustavo A. R. Silva
2017-10-30 23:33 ` Gustavo A. R. Silva
2017-10-31 2:33 ` Gustavo A. R. Silva
2017-10-31 4:12 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).