Re: [PATCH 2/3] media: iris: Document difference in size during allocation
From: Ricardo Ribalda
Date: Wed Dec 03 2025 - 08:18:03 EST
Hi Laurent
On Wed, 3 Dec 2025 at 10:17, Laurent Pinchart
<laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
>
> On Wed, Dec 03, 2025 at 08:55:35AM +0000, Ricardo Ribalda wrote:
> > As we get ready for kzalloc checking for invalid sizes, let's add
> > documentation for the cases where the size is different but valid.
> >
> > This patch fixes this cocci warning:
> > ./platform/qcom/iris/iris_hfi_gen2_command.c:1215:9-25: WARNING: casting value returned by memory allocation function to (struct iris_inst *) is useless.
> >
> > Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
> > ---
> > drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c | 10 +++++++++-
> > 1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c b/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
> > index f9129553209922fda548ca320494ae6ae797854c..ab91afd0597045bd876d0411b08b5a3421b12c70 100644
> > --- a/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
> > +++ b/drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c
> > @@ -1212,5 +1212,13 @@ void iris_hfi_gen2_command_ops_init(struct iris_core *core)
> >
> > struct iris_inst *iris_hfi_gen2_get_instance(void)
> > {
> > - return (struct iris_inst *)kzalloc(sizeof(struct iris_inst_hfi_gen2), GFP_KERNEL);
> > + struct iris_inst_hfi_gen2 *out;
> > +
> > + /*
> > + * The allocation is intentionally larger. The first member of
> > + * struct iris_hfi_gen2 is struct iris_inst.
> > + */
> > + out = kzalloc(sizeof(*out), GFP_KERNEL);
> > +
> > + return (struct iris_inst *)out;
>
> return &out->inst;
>
> would be more readable. You can then drop the comment.
It looks better, and it is more robust. Thanks
I prefer to leave a small comment though:
+ struct iris_inst_hfi_gen2 *out;
+
+ /* The allocation is intentionally larger than struct iris_inst. */
+ out = kzalloc(sizeof(*out), GFP_KERNEL);
+
+ return &out->inst;
Regards
>
> > }
> >
>
> --
> Regards,
>
> Laurent Pinchart
--
Ricardo Ribalda