lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 5 Jun 2019 08:27:03 +0200
From:   Jiri Slaby <jslaby@...e.cz>
To:     Gen Zhang <blackgod016574@...il.com>, rafael@...nel.org,
        gregkh@...uxfoundation.org
Cc:     jonathanh@...dia.com, linux-kernel@...r.kernel.org,
        luojiaxing@...wei.com
Subject: Re: [devm_kfree() usage] When should devm_kfree() be used?

On 25. 05. 19, 4:03, Gen Zhang wrote:
> devm_kmalloc() is used to allocate memory for a driver dev. Comments
> above the definition and doc 
> (https://www.kernel.org/doc/Documentation/driver-model/devres.txt) all
> imply that allocated the memory is automatically freed on driver attach,
> no matter allocation fail or not. However, I examined the code, and
> there are many sites that devm_kfree() is used to free devm_kmalloc().
> e.g. hisi_sas_debugfs_init() in drivers/scsi/hisi_sas/hisi_sas_main.c.

The guy who added the code in:
commit eb1c2b72b7694c984d520300c901f5fc1fa8ea9e
Author: Luo Jiaxing <luojiaxing@...wei.com>
Date:   Wed Dec 19 23:56:40 2018 +0800

    scsi: hisi_sas: Alloc debugfs snapshot buffer memory for all registers

seems to be as confused as you are.

> So I am totally confused about this issue. Can anybody give me some
> guidance? When should we use devm_kfree()?

Whenever you want to free the memory earlier than on ->remove or failed
->probe. For whatever reason.

thanks,
-- 
js
suse labs

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ