From: Sam Ravnborg <sam@ravnborg.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-fbdev@vger.kernel.org,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: Re: [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc()
Date: Sat, 20 Jun 2020 11:27:19 +0000 [thread overview]
Message-ID: <20200620112719.GC16901@ravnborg.org> (raw)
In-Reply-To: <20200617175647.GA26370@embeddedor>
Hi Gustavo.
On Wed, Jun 17, 2020 at 12:56:47PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
>
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
struct_size is defined in overflow.h - which is not included by fs.h.
So we rely on overflow.h being pulled in by some other header - maybe
slab.h in this case.
Seems fragile, should this patch add an include of overflow.h?
Sam
> ---
> include/linux/fb.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index 3b4b2f0c6994..2b530e6d86e4 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -506,8 +506,9 @@ struct fb_info {
> };
>
> static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
> - struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct)
> - + max_num * sizeof(struct aperture), GFP_KERNEL);
> + struct apertures_struct *a;
> +
> + a = kzalloc(struct_size(a, ranges, max_num), GFP_KERNEL);
> if (!a)
> return NULL;
> a->count = max_num;
> --
> 2.27.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Sam Ravnborg <sam@ravnborg.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-fbdev@vger.kernel.org,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: Re: [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc()
Date: Sat, 20 Jun 2020 13:27:19 +0200 [thread overview]
Message-ID: <20200620112719.GC16901@ravnborg.org> (raw)
In-Reply-To: <20200617175647.GA26370@embeddedor>
Hi Gustavo.
On Wed, Jun 17, 2020 at 12:56:47PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
>
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
struct_size is defined in overflow.h - which is not included by fs.h.
So we rely on overflow.h being pulled in by some other header - maybe
slab.h in this case.
Seems fragile, should this patch add an include of overflow.h?
Sam
> ---
> include/linux/fb.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index 3b4b2f0c6994..2b530e6d86e4 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -506,8 +506,9 @@ struct fb_info {
> };
>
> static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
> - struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct)
> - + max_num * sizeof(struct aperture), GFP_KERNEL);
> + struct apertures_struct *a;
> +
> + a = kzalloc(struct_size(a, ranges, max_num), GFP_KERNEL);
> if (!a)
> return NULL;
> a->count = max_num;
> --
> 2.27.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Sam Ravnborg <sam@ravnborg.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc()
Date: Sat, 20 Jun 2020 13:27:19 +0200 [thread overview]
Message-ID: <20200620112719.GC16901@ravnborg.org> (raw)
In-Reply-To: <20200617175647.GA26370@embeddedor>
Hi Gustavo.
On Wed, Jun 17, 2020 at 12:56:47PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
>
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
struct_size is defined in overflow.h - which is not included by fs.h.
So we rely on overflow.h being pulled in by some other header - maybe
slab.h in this case.
Seems fragile, should this patch add an include of overflow.h?
Sam
> ---
> include/linux/fb.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index 3b4b2f0c6994..2b530e6d86e4 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -506,8 +506,9 @@ struct fb_info {
> };
>
> static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
> - struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct)
> - + max_num * sizeof(struct aperture), GFP_KERNEL);
> + struct apertures_struct *a;
> +
> + a = kzalloc(struct_size(a, ranges, max_num), GFP_KERNEL);
> if (!a)
> return NULL;
> a->count = max_num;
> --
> 2.27.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-06-20 11:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20200617175132eucas1p2f1ea5f3b2f0d5cdb3277577ac8564c3f@eucas1p2.samsung.com>
2020-06-17 17:56 ` [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2020-06-17 17:56 ` Gustavo A. R. Silva
2020-06-17 17:56 ` Gustavo A. R. Silva
2020-06-20 11:27 ` Sam Ravnborg [this message]
2020-06-20 11:27 ` Sam Ravnborg
2020-06-20 11:27 ` Sam Ravnborg
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
2020-07-10 14:23 ` Bartlomiej Zolnierkiewicz
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=20200620112719.GC16901@ravnborg.org \
--to=sam@ravnborg.org \
--cc=b.zolnierkie@samsung.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.