Re: [PATCH] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()

From: T Pratham

Date: Sat Jun 13 2026 - 15:30:29 EST


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@xxxxxxxxx>
> Reported-by: Dan Carpenter <error27@xxxxxxxxx>
> Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@xxxxxxxxx/
> Signed-off-by: Mert Seftali <mertsftl@xxxxxxxxx>
> ---
> 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@xxxxxx>

--
Regards
T Pratham <t-pratham@xxxxxx>