mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Su Hui <suhui@nfschina.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Ben Skeggs <bskeggs@redhat.com>,
	Karol Herbst <kherbst@redhat.com>, Lyude Paul <lyude@redhat.com>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	airlied@redhat.com, dri-devel@lists.freedesktop.org,
	nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] drm/nouveau/nvif: use struct_size()
Date: Thu, 1 Jun 2023 08:59:32 +0800	[thread overview]
Message-ID: <a3905de3-265a-b69b-10f7-044bc18808b0@nfschina.com> (raw)
In-Reply-To: <00e84595-e2c9-48ea-8737-18da34eaafbf@kili.mountain>

On 2023/5/31 16:31, Dan Carpenter wrote:
> On Wed, May 31, 2023 at 12:38:26PM +0800, Su Hui wrote:
>> Use struct_size() instead of hand writing it.
>> This is less verbose and more informative.
>>
>> Signed-off-by: Su Hui <suhui@nfschina.com>
>> ---
>>   drivers/gpu/drm/nouveau/nvif/object.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nvif/object.c b/drivers/gpu/drm/nouveau/nvif/object.c
>> index 4d1aaee8fe15..4bd693aa4ee0 100644
>> --- a/drivers/gpu/drm/nouveau/nvif/object.c
>> +++ b/drivers/gpu/drm/nouveau/nvif/object.c
>> @@ -65,7 +65,7 @@ nvif_object_sclass_get(struct nvif_object *object, struct nvif_sclass **psclass)
>>   	u32 size;
>>   
>>   	while (1) {
>> -		size = sizeof(*args) + cnt * sizeof(args->sclass.oclass[0]);
>> +		size = struct_size(args, sclass.oclass, cnt);
> This is from the original code, but now that you are using the
> struct_size() macro static checkers will complain about it.  (Maybe they
> don't yet?).  size is a u32.  Never save struct_size() returns to
> anything except unsigned long or size_t.  (ssize_t is also fine, I
> suppose).  Otherwise, you do not benefit from the integer overflow
> checking.
Sorry, I don't notice the issue caused by type size.
You are right, this patch is wrong because of the type mismatch.
Thanks for your reply!

Su Hui

>>   		if (!(args = kmalloc(size, GFP_KERNEL)))
>>   			return -ENOMEM;
>>   		args->ioctl.version = 0;
> regards,
> dan carpenter

      reply	other threads:[~2023-06-01  0:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  4:38 Su Hui
2023-05-31  8:31 ` Dan Carpenter
2023-06-01  0:59   ` Su Hui [this message]

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=a3905de3-265a-b69b-10f7-044bc18808b0@nfschina.com \
    --to=suhui@nfschina.com \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=bskeggs@redhat.com \
    --cc=dan.carpenter@linaro.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kherbst@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®