Re: [PATCH 2/2] [PATCH 2/2] staging:glib:hp_82335: Refactor kzalloc size calculation to use pointer dereference

From: Dan Carpenter
Date: Tue Feb 18 2025 - 08:13:01 EST


On Mon, Feb 17, 2025 at 06:26:17PM +0530, Ravi Kumar kairi wrote:
> From: Ravi Kumar Kairi <kumarkairiravi@xxxxxxxxx>
>
> Replaced sizeof(struct hp82335_priv) with sizeof(*board->private_data)
> *as checkpatch* suggested.
>
> Signed-off-by: Ravi Kumar Kairi <kumarkairiravi@xxxxxxxxx>
> ---
> drivers/staging/gpib/hp_82335/hp82335.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gpib/hp_82335/hp82335.c b/drivers/staging/gpib/hp_82335/hp82335.c
> index f1c2045570..66557d6964 100644
> --- a/drivers/staging/gpib/hp_82335/hp82335.c
> +++ b/drivers/staging/gpib/hp_82335/hp82335.c
> @@ -205,7 +205,7 @@ static gpib_interface_t hp82335_interface = {
>
> static int hp82335_allocate_private(gpib_board_t *board)
> {
> - board->private_data = kzalloc(sizeof(struct hp82335_priv), GFP_KERNEL);
> + board->private_data = kzalloc(sizeof(*board->private_data), GFP_KERNEL);

No, this doesn't work. board->private_data is a void pointer.

I recently wrote a Smatch check for this kind of bug, but I was letting
someone send all the fixes before I publish it.

regards,
dan carpenter