* [PATCH] net: ocelot_board: fix a NULL pointer dereference
@ 2019-03-11 6:36 Kangjie Lu
2019-03-11 10:26 ` Alexandre Belloni
0 siblings, 1 reply; 5+ messages in thread
From: Kangjie Lu @ 2019-03-11 6:36 UTC (permalink / raw)
To: kjlu
Cc: pakki001, Alexandre Belloni, Microchip Linux Driver Support,
David S. Miller, netdev, linux-kernel
In case devm_kcalloc fails, the fix returns -ENOMEM to avoid
NULL pointer dereference.
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c
index e7f90101d2e0..af68abf1632a 100644
--- a/drivers/net/ethernet/mscc/ocelot_board.c
+++ b/drivers/net/ethernet/mscc/ocelot_board.c
@@ -256,6 +256,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
sizeof(struct ocelot_port *), GFP_KERNEL);
+ if (!ocelot->ports)
+ return -ENOMEM;
INIT_LIST_HEAD(&ocelot->multicast);
ocelot_init(ocelot);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ocelot_board: fix a NULL pointer dereference
2019-03-11 6:36 [PATCH] net: ocelot_board: fix a NULL pointer dereference Kangjie Lu
@ 2019-03-11 10:26 ` Alexandre Belloni
2019-03-11 14:14 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Belloni @ 2019-03-11 10:26 UTC (permalink / raw)
To: Kangjie Lu
Cc: pakki001, Microchip Linux Driver Support, David S. Miller,
netdev, linux-kernel
On 11/03/2019 01:36:32-0500, Kangjie Lu wrote:
> In case devm_kcalloc fails, the fix returns -ENOMEM to avoid
> NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
> drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c
> index e7f90101d2e0..af68abf1632a 100644
> --- a/drivers/net/ethernet/mscc/ocelot_board.c
> +++ b/drivers/net/ethernet/mscc/ocelot_board.c
> @@ -256,6 +256,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
>
> ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
> sizeof(struct ocelot_port *), GFP_KERNEL);
> + if (!ocelot->ports)
> + return -ENOMEM;
>
> INIT_LIST_HEAD(&ocelot->multicast);
> ocelot_init(ocelot);
> --
> 2.17.1
>
--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ocelot_board: fix a NULL pointer dereference
2019-03-11 10:26 ` Alexandre Belloni
@ 2019-03-11 14:14 ` Eric Dumazet
2019-03-11 17:39 ` David Miller
2019-03-23 3:33 ` Kangjie Lu
0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2019-03-11 14:14 UTC (permalink / raw)
To: Alexandre Belloni, Kangjie Lu
Cc: pakki001, Microchip Linux Driver Support, David S. Miller,
netdev, linux-kernel
On 03/11/2019 03:26 AM, Alexandre Belloni wrote:
> On 11/03/2019 01:36:32-0500, Kangjie Lu wrote:
>> In case devm_kcalloc fails, the fix returns -ENOMEM to avoid
>> NULL pointer dereference.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
>
A proper error path is needed to avoid memory leaks.
>> ---
>> drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c
>> index e7f90101d2e0..af68abf1632a 100644
>> --- a/drivers/net/ethernet/mscc/ocelot_board.c
>> +++ b/drivers/net/ethernet/mscc/ocelot_board.c
>> @@ -256,6 +256,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
>>
>> ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
>> sizeof(struct ocelot_port *), GFP_KERNEL);
>> + if (!ocelot->ports)
>> + return -ENOMEM;
>>
>> INIT_LIST_HEAD(&ocelot->multicast);
>> ocelot_init(ocelot);
>> --
>> 2.17.1
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ocelot_board: fix a NULL pointer dereference
2019-03-11 14:14 ` Eric Dumazet
@ 2019-03-11 17:39 ` David Miller
2019-03-23 3:33 ` Kangjie Lu
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2019-03-11 17:39 UTC (permalink / raw)
To: eric.dumazet
Cc: alexandre.belloni, kjlu, pakki001, UNGLinuxDriver, netdev, linux-kernel
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 11 Mar 2019 07:14:58 -0700
>
>
> On 03/11/2019 03:26 AM, Alexandre Belloni wrote:
>> On 11/03/2019 01:36:32-0500, Kangjie Lu wrote:
>>> In case devm_kcalloc fails, the fix returns -ENOMEM to avoid
>>> NULL pointer dereference.
>>>
>>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>> Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
>>
>
> A proper error path is needed to avoid memory leaks.
This seems to be a major chronic problem with all of these patches.
Kangjie please put more care into the patches you are submitting.
You absolutely CANNOT just add a error check and return, you must
handle releasing resources and any other necessary cleanups.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ocelot_board: fix a NULL pointer dereference
2019-03-11 14:14 ` Eric Dumazet
2019-03-11 17:39 ` David Miller
@ 2019-03-23 3:33 ` Kangjie Lu
1 sibling, 0 replies; 5+ messages in thread
From: Kangjie Lu @ 2019-03-23 3:33 UTC (permalink / raw)
To: Eric Dumazet
Cc: Alexandre Belloni, pakki001, Microchip Linux Driver Support,
David S. Miller, netdev, linux-kernel
> On Mar 11, 2019, at 9:14 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
>
> On 03/11/2019 03:26 AM, Alexandre Belloni wrote:
>> On 11/03/2019 01:36:32-0500, Kangjie Lu wrote:
>>> In case devm_kcalloc fails, the fix returns -ENOMEM to avoid
>>> NULL pointer dereference.
>>>
>>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>> Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
>>
>
> A proper error path is needed to avoid memory leaks.
Which objects require free specifically? The memory allocated with
devm_kzalloc() is freed automatically. No need to explicitly free it
again.
-Kangjie
>
>>> ---
>>> drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c
>>> index e7f90101d2e0..af68abf1632a 100644
>>> --- a/drivers/net/ethernet/mscc/ocelot_board.c
>>> +++ b/drivers/net/ethernet/mscc/ocelot_board.c
>>> @@ -256,6 +256,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
>>>
>>> ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
>>> sizeof(struct ocelot_port *), GFP_KERNEL);
>>> + if (!ocelot->ports)
>>> + return -ENOMEM;
>>>
>>> INIT_LIST_HEAD(&ocelot->multicast);
>>> ocelot_init(ocelot);
>>> --
>>> 2.17.1
>>>
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-23 3:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-11 6:36 [PATCH] net: ocelot_board: fix a NULL pointer dereference Kangjie Lu
2019-03-11 10:26 ` Alexandre Belloni
2019-03-11 14:14 ` Eric Dumazet
2019-03-11 17:39 ` David Miller
2019-03-23 3:33 ` Kangjie Lu
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.