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

Pandey, Radhey Shyam radheys at amd.com
Thu Aug 13 02:11:37 PDT 2026


On 8/11/2026 4:09 PM, tarunsahu at google.com wrote:
> "Pandey, Radhey Shyam" <radheys at amd.com> 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 <tarunsahu at google.com>
>>
>> Thanks for the patch. FYI, this issue is already being addressed in an
>> ongoing series.
>> https://lore.kernel.org/all/20260724171945.2812749-5-shubhrajyoti.datta@amd.com/
>>
> 
> 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?
> 

Please drop it from your series as the fix done in Shubhrajyoti's
series is complete.

Thanks,
Radhey

> ~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;
>>>    }
>>>    




More information about the linux-arm-kernel mailing list