lkml.org 
[lkml]   [2019]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] net: ocelot_board: fix a NULL pointer dereference
From
Date


> 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
>>>
>>

\
 
 \ /
  Last update: 2019-03-23 04:34    [W:0.036 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site