From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
GR-QLogic-Storage-Upstream@marvell.com,
Nilesh Javali <njavali@marvell.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH 2/2][next] scsi: qla2xxx: Use struct_size() in code related to struct ct_sns_gpnft_rsp
Date: Sat, 19 Nov 2022 01:20:09 -0600 [thread overview]
Message-ID: <Y3iDqTPFdoUQ3a0f@work> (raw)
In-Reply-To: <202211182309.D5AC082E3@keescook>
On Fri, Nov 18, 2022 at 11:10:44PM -0800, Kees Cook wrote:
> On Fri, Nov 18, 2022 at 05:47:56PM -0600, Gustavo A. R. Silva wrote:
> > Prefer struct_size() over open-coded versions of idiom:
> >
> > sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
> >
> > where count is the max number of items the flexible array is supposed to
> > contain.
> >
> > Link: https://github.com/KSPP/linux/issues/160
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > ---
> > drivers/scsi/qla2xxx/qla_gs.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
> > index 69d3bc795f90..27e1df56b0fb 100644
> > --- a/drivers/scsi/qla2xxx/qla_gs.c
> > +++ b/drivers/scsi/qla2xxx/qla_gs.c
> > @@ -4072,9 +4072,8 @@ int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp)
> > }
> > sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
> >
> > - rspsz = sizeof(struct ct_sns_gpnft_rsp) +
> > - (vha->hw->max_fibre_devices *
> > - sizeof(struct ct_sns_gpn_ft_data));
> > + rspsz = struct_size((struct ct_sns_gpnft_rsp *)0, entries,
> > + vha->hw->max_fibre_devices);
>
> This should be able to use sp->u.iocb_cmd.u.ctarg.rsp instead of the
> explicit struct with a NULL. (It's just using typeof() internally, so
> it's okay that it isn't allocated yet.)
mmh... yeah; and considering they're already going all the way down to
sp->u.iocb_cmd.u.ctarg.req_size, I think accessing sp->u.iocb_cmd.u.ctarg.rsp
is perfectly fine. :)
I'll respin. Thanks for the feedback!
--
Gustavo
>
> -Kees
>
> >
> > sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
> > rspsz,
> > --
> > 2.34.1
> >
>
> --
> Kees Cook
next prev parent reply other threads:[~2022-11-19 7:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 23:46 [PATCH 0/2][next] scsi: qla2xxx: Replace one-element array with flexible-array member Gustavo A. R. Silva
2022-11-18 23:47 ` [PATCH 1/2][next] scsi: qla2xxx: Replace one-element array with DECLARE_FLEX_ARRAY() helper Gustavo A. R. Silva
2022-11-19 7:09 ` Kees Cook
2022-11-19 8:44 ` Christophe JAILLET
2022-11-19 8:56 ` Gustavo A. R. Silva
2022-11-19 10:23 ` Christophe JAILLET
2022-11-19 19:03 ` Gustavo A. R. Silva
2022-11-18 23:47 ` [PATCH 2/2][next] scsi: qla2xxx: Use struct_size() in code related to struct ct_sns_gpnft_rsp Gustavo A. R. Silva
2022-11-19 7:10 ` Kees Cook
2022-11-19 7:20 ` Gustavo A. R. Silva [this message]
2022-11-19 7:49 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y3iDqTPFdoUQ3a0f@work \
--to=gustavoars@kernel.org \
--cc=GR-QLogic-Storage-Upstream@marvell.com \
--cc=jejb@linux.ibm.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=njavali@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).