Re: [PATCH 3/4] EDAC/versalnet: use put_device() on device_register() failure

[email protected]
Newsgroups org.kernel.vger.linux-edac,dev.linux.lists.driver-core,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.ozlabs.lists.linuxppc-dev
Message-ID <[email protected]>
"Pandey, Radhey Shyam" <[email protected]> writes:

> On 8/10/2026 9:58 PM, Tarun Sahu wrote:
>> When device_register() fails, calling kfree(dev) directly bypasses the
>> device_release() callback (versal_edac_release) and leaks the allocated
>> driver core structures.
>> 
>> Fix this by calling put_device(dev) when device_register() returns an
>> error, ensuring proper refcount decrement and release cleanup.
>> 
>> Signed-off-by: Tarun Sahu <[email protected]>
>
> Thanks for the patch. FYI, this issue is already being addressed in an
> ongoing series.
> https://lore.kernel.org/all/[email protected]/
>

That is good. Should it go as saperate patch or it fits very well with
the above series. I will drop it incase of later. WDYT?

~Tarun

> -Radhey
>
>> ---
>>   drivers/edac/versalnet_edac.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
>> index 97ec05d68bbb..2912b3658915 100644
>> --- a/drivers/edac/versalnet_edac.c
>> +++ b/drivers/edac/versalnet_edac.c
>> @@ -829,8 +829,10 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
>>   	dev->release = versal_edac_release;
>>   
>>   	rc = device_register(dev);
>> -	if (rc)
>> +	if (rc) {
>> +		put_device(dev);
>>   		goto err_mc_free;
>> +	}
>>   
>>   	mci->pdev = dev;
>>   	mc_init(mci, dev);
>> @@ -852,9 +854,9 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
>>   	device_unregister(mci->pdev);
>>   err_mc_free:
>>   	edac_mc_free(mci);
>> +	return rc;
>>   err_dev_free:
>>   	kfree(dev);
>> -
>>   	return rc;
>>   }
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.