[PATCH v3] fsi: Aspeed: Fix a potential double free

Christophe JAILLET christophe.jaillet at wanadoo.fr
Tue Feb 22 05:08:32 AEDT 2022

Le 21/02/2022 à 10:24, Joel Stanley a écrit :
> Hi Christophe,
> Thanks for the patch.
> On Sun, 9 Jan 2022 at 21:56, Christophe JAILLET
> <christophe.jaillet at wanadoo.fr> wrote:
>> A struct device can never be devm_alloc()'ed.
>> Here, it is embedded in "struct fsi_master", and "struct fsi_master" is
>> embedded in "struct fsi_master_aspeed".
>> Since "struct device" is embedded, the data structure embedding it must be
>> released with the release function, as is already done here.
>> So use kzalloc() instead of devm_kzalloc() when allocating "aspeed" and
>> update all error handling branches accordingly.
> This looks like a problem with the design of the fsi master structure.
> It's a common pattern to devm_alloc the platform devices as they are
> probed, the fsi masters all embed a copy of struct fsi_master, which
> as you say embeds struct device.
> Can we learn from other bus drivers (eg i2c?) how we should lay out
> these structures?
I won't do it myself.

This goes beyond my knowledge and without the possibility to test it, it 
would be just some random trial and error (as I did in the first broken 
version of this patch).


More information about the Linux-aspeed mailing list