Message ID | 20230531043826.991183-1-suhui@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2639801vqr; Tue, 30 May 2023 21:59:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JzTeBNnpZng4V2qtp5GPgcZFavEAqhtr62G9prbvzL8dotO2MCYwSyRSiwG7KovqW/eqB X-Received: by 2002:a17:903:32c5:b0:1a2:6257:36b9 with SMTP id i5-20020a17090332c500b001a2625736b9mr5680752plr.31.1685509152568; Tue, 30 May 2023 21:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685509152; cv=none; d=google.com; s=arc-20160816; b=YQg5mz0wlWLLKSRMhC/LZZIo7nR+lDkT0jwfhK8uSSj6SHOlnAPPc35gCe9tRKWeSV wb0+1+xe4vLwOdkVic4Mmd55uOoWIxNcmv1O0eks0AW9nM/1ECvP6RMFabCr8OKTKZM7 o9GP4xpPc/M6lfHSQdvoMGAzJTqjfgyFro8HTawnFyAGChEG31dyiqVpk/DHiNP3s6Ha bqMeZ13tknWku72fijfzESe5CQEmYecvnA82el7PqFd2CjcmLi4Q5vPmmRmpl/6b+tPf UQ8UVoINOqTih3TomPJfwFKLqoM7MXPiKm70W4+n+p5dvXwaeusNPCDRHFVQJOHw7Vlq +zNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Vo1RGMNItuSe9MEKQ+OuyMCY/Y9xiLUNkbUn4UzI2+k=; b=EAtmbxD26jAE9LKKCiem+HG+bXTKZ9gKM2vWSZtU1nM7epeHAGCuzxVvxcmVMFuqc8 naBv7cark0MsCe3Ps+zbdg+QI8c6CKlGqPUpoLxWgsActVs5TEL7thc9mbTkp4vIrZN+ rQeijVez/Ao25Zk3rFywadVGFz2K5bJEFvvavFk42xTEHUF3f3Xrv2dFyyrS41YfWGox 04n0G50Tlso/PHvCCeM0tngncNF9Ko5gSEhHCGthB2LxRz7M1vOBKGxBE1/PzN4P9Oxn nOOJxkPvyYznQtGzibpFobfClayFbX5soT2Af4+4cXWc904F2tuFzPni8gMY8h1vuzJW jilg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a17090341d100b001b0489a019asi225827ple.471.2023.05.30.21.58.55; Tue, 30 May 2023 21:59:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234040AbjEaEi5 (ORCPT <rfc822;callmefire3@gmail.com> + 99 others); Wed, 31 May 2023 00:38:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230001AbjEaEiz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 31 May 2023 00:38:55 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id E6CBF97; Tue, 30 May 2023 21:38:53 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 26EE7180106EEA; Wed, 31 May 2023 12:38:29 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui <suhui@nfschina.com> To: 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> Cc: airlied@redhat.com, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Su Hui <suhui@nfschina.com> Subject: [PATCH] drm/nouveau/nvif: use struct_size() Date: Wed, 31 May 2023 12:38:26 +0800 Message-Id: <20230531043826.991183-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767384445273519838?= X-GMAIL-MSGID: =?utf-8?q?1767384445273519838?= |
Series |
drm/nouveau/nvif: use struct_size()
|
|
Commit Message
Su Hui
May 31, 2023, 4:38 a.m. UTC
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(-)
Comments
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. > if (!(args = kmalloc(size, GFP_KERNEL))) > return -ENOMEM; > args->ioctl.version = 0; regards, dan carpenter
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
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); if (!(args = kmalloc(size, GFP_KERNEL))) return -ENOMEM; args->ioctl.version = 0;