* [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
@ 2026-06-13 8:58 Mert Seftali
2026-06-13 19:30 ` T Pratham
2026-07-03 8:37 ` Herbert Xu
0 siblings, 2 replies; 5+ messages in thread
From: Mert Seftali @ 2026-06-13 8:58 UTC (permalink / raw)
To: T Pratham, Herbert Xu
Cc: David S . Miller, Dan Carpenter, linux-crypto, linux-kernel,
Mert Seftali, kernel test robot
dthe_get_dev() fetches a device from the global device list with
list_first_entry() and then checks the result for NULL. However,
list_first_entry() never returns NULL: on an empty list it returns a
bogus pointer computed from the list head. The NULL check is therefore
dead code, and an empty list would be treated as a valid entry and
moved around as if it were a real device.
Use list_first_entry_or_null() so the existing NULL check works as
intended and an empty list is handled gracefully.
Fixes: 52f641bc63a4 ("crypto: ti - Add driver for DTHE V2 AES Engine (ECB, CBC)")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@intel.com/
Signed-off-by: Mert Seftali <mertsftl@gmail.com>
---
drivers/crypto/ti/dthev2-common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/crypto/ti/dthev2-common.c b/drivers/crypto/ti/dthev2-common.c
index a2ad79bec105..cc0244938267 100644
--- a/drivers/crypto/ti/dthev2-common.c
+++ b/drivers/crypto/ti/dthev2-common.c
@@ -40,7 +40,7 @@ struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx)
return ctx->dev_data;
spin_lock_bh(&dthe_dev_list.lock);
- dev_data = list_first_entry(&dthe_dev_list.dev_list, struct dthe_data, list);
+ dev_data = list_first_entry_or_null(&dthe_dev_list.dev_list, struct dthe_data, list);
if (dev_data)
list_move_tail(&dev_data->list, &dthe_dev_list.dev_list);
spin_unlock_bh(&dthe_dev_list.lock);
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
2026-06-13 8:58 [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() Mert Seftali
@ 2026-06-13 19:30 ` T Pratham
2026-07-03 8:37 ` Herbert Xu
1 sibling, 0 replies; 5+ messages in thread
From: T Pratham @ 2026-06-13 19:30 UTC (permalink / raw)
To: Mert Seftali, Herbert Xu
Cc: David S . Miller, Dan Carpenter, linux-crypto, linux-kernel,
kernel test robot
On 13-06-2026 14:28, Mert Seftali wrote:
> dthe_get_dev() fetches a device from the global device list with
> list_first_entry() and then checks the result for NULL. However,
> list_first_entry() never returns NULL: on an empty list it returns a
> bogus pointer computed from the list head. The NULL check is therefore
> dead code, and an empty list would be treated as a valid entry and
> moved around as if it were a real device.
>
> Use list_first_entry_or_null() so the existing NULL check works as
> intended and an empty list is handled gracefully.
>
> Fixes: 52f641bc63a4 ("crypto: ti - Add driver for DTHE V2 AES Engine (ECB, CBC)")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@intel.com/
> Signed-off-by: Mert Seftali <mertsftl@gmail.com>
> ---
> drivers/crypto/ti/dthev2-common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/ti/dthev2-common.c b/drivers/crypto/ti/dthev2-common.c
> index a2ad79bec105..cc0244938267 100644
> --- a/drivers/crypto/ti/dthev2-common.c
> +++ b/drivers/crypto/ti/dthev2-common.c
> @@ -40,7 +40,7 @@ struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx)
> return ctx->dev_data;
>
> spin_lock_bh(&dthe_dev_list.lock);
> - dev_data = list_first_entry(&dthe_dev_list.dev_list, struct dthe_data, list);
> + dev_data = list_first_entry_or_null(&dthe_dev_list.dev_list, struct dthe_data, list);
> if (dev_data)
> list_move_tail(&dev_data->list, &dthe_dev_list.dev_list);
> spin_unlock_bh(&dthe_dev_list.lock);
LGTM.
Reviewed-by: T Pratham <t-pratham@ti.com>
--
Regards
T Pratham <t-pratham@ti.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
2026-06-13 8:58 [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() Mert Seftali
2026-06-13 19:30 ` T Pratham
@ 2026-07-03 8:37 ` Herbert Xu
2026-07-03 14:09 ` Mert Seftali
2026-07-29 11:55 ` T Pratham
1 sibling, 2 replies; 5+ messages in thread
From: Herbert Xu @ 2026-07-03 8:37 UTC (permalink / raw)
To: Mert Seftali
Cc: T Pratham, David S . Miller, Dan Carpenter, linux-crypto,
linux-kernel, kernel test robot
On Sat, Jun 13, 2026 at 10:58:58AM +0200, Mert Seftali wrote:
> dthe_get_dev() fetches a device from the global device list with
> list_first_entry() and then checks the result for NULL. However,
> list_first_entry() never returns NULL: on an empty list it returns a
> bogus pointer computed from the list head. The NULL check is therefore
> dead code, and an empty list would be treated as a valid entry and
> moved around as if it were a real device.
>
> Use list_first_entry_or_null() so the existing NULL check works as
> intended and an empty list is handled gracefully.
>
> Fixes: 52f641bc63a4 ("crypto: ti - Add driver for DTHE V2 AES Engine (ECB, CBC)")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@intel.com/
> Signed-off-by: Mert Seftali <mertsftl@gmail.com>
> ---
> drivers/crypto/ti/dthev2-common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
This only fixes the symptom of the problem. But the root goes
deeper.
The main issue is that the device can go away in the middle of
an operation. The driver needs to be handle it gracefully, and
certainly not by crashing the system because the associated memory
has been freed.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
2026-07-03 8:37 ` Herbert Xu
@ 2026-07-03 14:09 ` Mert Seftali
2026-07-29 11:55 ` T Pratham
1 sibling, 0 replies; 5+ messages in thread
From: Mert Seftali @ 2026-07-03 14:09 UTC (permalink / raw)
To: Herbert Xu
Cc: T Pratham, David S . Miller, Dan Carpenter, linux-crypto,
linux-kernel, kernel test robot
On Fri, 3 Jul 2026, Herbert Xu wrote:
> This only fixes the symptom of the problem. But the root goes deeper.
>
> The main issue is that the device can go away in the middle of an
> operation. [...]
Yeah agreed. my patch only covers the empty-list case the test robot
flagged but it doesn't touch the lifetime problem at all.
Doing that one properly is a much bigger change than a one-liner though, and
i'd rather take the time to understand the driver's lifecycle and do it right
than send you a half-baked fix. So, is the list_first_entry_or_null() change
still worth taking as a small correctness fix on its own or would you rather
drop it and sort the lifetime issue as a whole?
Thanks,
Mert
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
2026-07-03 8:37 ` Herbert Xu
2026-07-03 14:09 ` Mert Seftali
@ 2026-07-29 11:55 ` T Pratham
1 sibling, 0 replies; 5+ messages in thread
From: T Pratham @ 2026-07-29 11:55 UTC (permalink / raw)
To: Herbert Xu, Mert Seftali
Cc: David S . Miller, Dan Carpenter, linux-crypto, linux-kernel,
kernel test robot
On 7/3/26 14:07, Herbert Xu wrote:
> On Sat, Jun 13, 2026 at 10:58:58AM +0200, Mert Seftali wrote:
>> dthe_get_dev() fetches a device from the global device list with
>> list_first_entry() and then checks the result for NULL. However,
>> list_first_entry() never returns NULL: on an empty list it returns a
>> bogus pointer computed from the list head. The NULL check is therefore
>> dead code, and an empty list would be treated as a valid entry and
>> moved around as if it were a real device.
>>
>> Use list_first_entry_or_null() so the existing NULL check works as
>> intended and an empty list is handled gracefully.
>>
>> Fixes: 52f641bc63a4 ("crypto: ti - Add driver for DTHE V2 AES Engine (ECB, CBC)")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Reported-by: Dan Carpenter <error27@gmail.com>
>> Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@intel.com/
>> Signed-off-by: Mert Seftali <mertsftl@gmail.com>
>> ---
>> drivers/crypto/ti/dthev2-common.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> This only fixes the symptom of the problem. But the root goes
> deeper.
>
> The main issue is that the device can go away in the middle of
> an operation. The driver needs to be handle it gracefully, and
> certainly not by crashing the system because the associated memory
> has been freed.
>
> Thanks,
This is not possible here as the device is part of the SoC. That being
said, I'll implement this handling to have a more correct driver. In the
meanwhile, the above empty list fix can be applied.
--
Regards
T Pratham <t-pratham@ti.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-29 11:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-13 8:58 [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() Mert Seftali
2026-06-13 19:30 ` T Pratham
2026-07-03 8:37 ` Herbert Xu
2026-07-03 14:09 ` Mert Seftali
2026-07-29 11:55 ` T Pratham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox