public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
To: Johan Jonker <jbx6244@gmail.com>
Cc: Tom Rini <trini@konsulko.com>,
	Kever Yang <kever.yang@rock-chips.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Heiko Schocher <hs@denx.de>,
	Alexey Romanov <avromanov@salutedevices.com>,
	Michael Trimarchi <michael@amarulasolutions.com>,
	Sean Anderson <seanga2@gmail.com>,
	Quentin Schulz <quentin.schulz@cherry.de>,
	u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH 1/3] rockchip: block: simplify rkmtd driver
Date: Mon, 21 Oct 2024 15:35:57 +0200	[thread overview]
Message-ID: <8bc4173f-ceb1-491f-bbdb-507a9ca96642@canonical.com> (raw)
In-Reply-To: <CAFLszTgt_5rpKg2XUW_h5_AU5zYssiO7cLtTEaz8w0_Q8zVh4A@mail.gmail.com>

On 10/19/24 13:50, Simon Glass wrote:
> Hi Johan,
> 
> On Fri, 18 Oct 2024 at 07:33, Johan Jonker <jbx6244@gmail.com> wrote:
>>
>>
>>
>> On 10/18/24 03:30, Heinrich Schuchardt wrote:
>>> By using blk_create_devicef() instead of blk_create_devicef() the driver
>>> can be simplified and brought into line with other block device drivers.
>>>
>>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>>> ---
>>>   drivers/block/rkmtd.c | 21 ++-------------------
>>>   1 file changed, 2 insertions(+), 19 deletions(-)
>>>
>>> diff --git a/drivers/block/rkmtd.c b/drivers/block/rkmtd.c
>>> index c55f052e51b..f84cacd7ead 100644
>>> --- a/drivers/block/rkmtd.c
>>> +++ b/drivers/block/rkmtd.c
>>> @@ -794,36 +794,19 @@ int rkmtd_init_plat(struct udevice *dev)
>>>        return 0;
>>>   }
>>>
>>> -static void rkmtd_blk_kmalloc_release(struct udevice *dev, void *res)
>>> -{
>>> -     /* noop */
>>> -}
>>> -
>>>   static int rkmtd_bind(struct udevice *dev)
>>>   {
>>>        struct rkmtd_dev *plat = dev_get_plat(dev);
>>> -     char dev_name[30], *str;
>>>        struct blk_desc *desc;
>>>        struct udevice *bdev;
>>>        int ret;
>>>
>>> -     snprintf(dev_name, sizeof(dev_name), "%s.%s", dev->name, "blk");
>>> -
>>
>>> -     str = devres_alloc(rkmtd_blk_kmalloc_release, strlen(dev_name) + 1, GFP_KERNEL);
>>
>> Hi Heinrich, Simon,
>>
>> The function strdup() is not an exact replacement for the devres_alloc() function in relation to a device.
>> It is in use for memory leak detection / device resource management.
>> Not sure what the status of that devres project currently is? Also tracking in general in relation to EFI and blk-class.
>>
>> https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/block/blk-uclass.c?ref_type=heads#L739
>>
>> https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/block/rkmtd.c?ref_type=heads#L812
>>
>> Test for this driver are based on work done by Simon.
>> https://source.denx.de/u-boot/u-boot/-/blob/master/test/dm/host.c?ref_type=heads#L71
>>
>> This rkmtd driver makes use of devm_kzalloc(). All the memory that rkmtd reserves is freed.
>> But if I remember well somehow I was not able to free all memory on unbind and was not able to find the source, so I didn't include that last test.
>> https://elixir.bootlin.com/u-boot/v2024.10/source/test/dm/rkmtd.c#L84
> 
> Yes, you can use that API. But I think Heinrich's patch is correct,
> and separate from your points here. Yes, blk_create_devicef()
> strdup()s the name, but it sets a flag indicating that it has done so.
> Then device_unbind() checks DM_FLAG_NAME_ALLOCED later. So the code
> should be equivalent.
> 
> Re the memory leak, I don't have any ideas, but test/dm/devres.c does
> have some checks for some of that. I have often wondered about having
> a way to store the filename and line (or just the line?) with every
> allocation, so we can list out what is left at the end, since valgrind
> doesn't work on target devices.
> 
> Regards,
> Simon

Hello Johan,

I hope that Simon's comment clarifies how freeing the string resource works.

Do you have a device to test this patch?

Best regards

Heinrich

  reply	other threads:[~2024-10-21 13:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18  1:30 [PATCH 0/3] block: make blk_create_device() static Heinrich Schuchardt
2024-10-18  1:30 ` [PATCH 1/3] rockchip: block: simplify rkmtd driver Heinrich Schuchardt
2024-10-18 13:33   ` Johan Jonker
2024-10-19 11:50     ` Simon Glass
2024-10-21 13:35       ` Heinrich Schuchardt [this message]
2024-10-22 19:58         ` Johan Jonker
2024-10-18  1:30 ` [PATCH 2/3] efi_driver: use blk_create_devicef() Heinrich Schuchardt
2024-10-18 14:57   ` Simon Glass
2024-10-18  1:30 ` [PATCH 3/3] block: make blk_create_device() static Heinrich Schuchardt
2024-10-18 14:52   ` Simon Glass
2024-10-21 10:49   ` Ilias Apalodimas
2024-10-24 20:42 ` (subset) [PATCH 0/3] " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bc4173f-ceb1-491f-bbdb-507a9ca96642@canonical.com \
    --to=heinrich.schuchardt@canonical.com \
    --cc=avromanov@salutedevices.com \
    --cc=hs@denx.de \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jbx6244@gmail.com \
    --cc=kever.yang@rock-chips.com \
    --cc=michael@amarulasolutions.com \
    --cc=quentin.schulz@cherry.de \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox