Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3433796ybi; Sun, 26 May 2019 23:23:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvuCMJ/81TT7Z2Td+p7fs3K77bKXIHDC06w0sxv35BVsR+9zTaJh7K7KIxprAtHH2FZCFe X-Received: by 2002:a17:90a:1ac5:: with SMTP id p63mr29229314pjp.8.1558938232583; Sun, 26 May 2019 23:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558938232; cv=none; d=google.com; s=arc-20160816; b=ZDwq9p6ew8Lek/j3ytjRzMIogclql5UTTU4Q26Nux+xVpo2Xgn01KPScxQ5UHV6Qkx D21RT7sD0jMrLT4J9RkCR4o1hTBEsR/9PmLooTKt102wSe0CDR7pMPM5M1aM80gC3p8Z u28IIgkoAOcLesZIoenATWF3DVYTEaSIy215/7nN9xRlssO9AaSaOGS2JbrPBbQJpM+6 O21osKq6baVC1IBr/+lEXKoGS28NK5Z/pSf8wgpHfOwgtmZb3g0z6qoRmlJ/bI+0pJ+I n7mwholWHSWjRIv5QjxlxMpeGZV0k7npisZQiXO8qsnaRl31kPSvNxuoDgD+nYcmMoBW XPtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YxJhbGCQeRIczqHCGhPIuHhpBpASyG3xpi/UjbzUnfo=; b=vtmLBMnwUxB5bJc4YO/AU9hTZ1FFGeuLzKlupSFXxxtyl8Ak0nPKRt1tv1tsa2mD0s Rle9dYSGiUqeJ8KkyYX1lNwub79RwDDvwtDojleI898jIGiNf0uBqtfZRRwbGO6yL9Ap VZNdrmOTAp9IfuBSXF0ocSxeEh5lRdLMfhKdBIO2oK5KVZivhnmjvj1ecX3SZndxgds/ AoEkOVd3+OmaOx5DeSL+VzduKGxjQyAW3mCzMCkPfa6FYCtA/r2BsVELYDQv67cJpxII 1fniGd008YCJDEbPt4tjzVs6CzrHYcLkE0kTjTf/7elkcIsMePWMSF/aZ2hyAb+WVN5d +BBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NDysXy6M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si15418403plq.387.2019.05.26.23.23.37; Sun, 26 May 2019 23:23:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NDysXy6M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726435AbfE0GVz (ORCPT + 99 others); Mon, 27 May 2019 02:21:55 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:46939 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbfE0GVy (ORCPT ); Mon, 27 May 2019 02:21:54 -0400 Received: by mail-vs1-f68.google.com with SMTP id x8so9855322vsx.13 for ; Sun, 26 May 2019 23:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YxJhbGCQeRIczqHCGhPIuHhpBpASyG3xpi/UjbzUnfo=; b=NDysXy6M9PCmJgS0IeywzxchLf6sY+7dg8ySoS/e/SL3T5KU2od4fBZz/WBReeMKgh nqvav4L/pw9U2lc22xl8FfLUb2tYWnLfcqSswbGS+dsl850aaH3v+ibBaUtjvyAhfn2I hJ842lR0yQjII3AFJtH0xFEhK/uMWS19Iwwn2tJI+GpLXhewvXsGO3bGMMJrgeE4EA07 rk4HnB3CBXkfCd4LQK8Jxd0V92ZgxEFJLBxdCF3hyBClHDPbHB6t1oH/+bCnsk7fKsYS 02vIBmAagz1uQM7zfBfdsJGX0huLwNiCwkdUj50fi8viH3V/ey5iuW+7X19APnKG/ylF thig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YxJhbGCQeRIczqHCGhPIuHhpBpASyG3xpi/UjbzUnfo=; b=UhJNLsBj9ve4R2kD88YDMt+haxoesB1A18T2GaEBa8KF+J8WLrNxI49QLoJYzi74IQ 58Q/U07hOwKRpyMN8giyi5rf3TVZEs8hBaPfP38X7vnVNSCCPSsuWNnsVuK7s+ArDc1Q jyDGKjEGJNAZKGKNR2zzIoMGwNeg2Wl8dDPOcm11Z/2/YqmYBH2zoL6EIZwCQB1gDpqN zt4sIpTJ+Z3jk/8+NG+xSuxbDcfEJG/o0f+b0PVgvvKD5NYJWFsRmi24u0p3lmwecBGn Q/XZfSxEnPIgfKkZQulzw0RRPe/d2+2C+F9bKIZ36j2bNexpZRuqD+cKBB0U/gUcy1E0 kAnQ== X-Gm-Message-State: APjAAAUHI8Y4Bqjplx7SjB/42zarC6xz2Bi1eRXT5BYn3MYkh18ppRjn kVYieuk58H1Qh4oD4SoFkiRipOObztwFTrNz0sM= X-Received: by 2002:a05:6102:1050:: with SMTP id h16mr33145472vsq.132.1558938113452; Sun, 26 May 2019 23:21:53 -0700 (PDT) MIME-Version: 1.0 References: <20190524171536.GA20883@embeddedor> In-Reply-To: <20190524171536.GA20883@embeddedor> From: Ben Skeggs Date: Mon, 27 May 2019 16:21:42 +1000 Message-ID: Subject: Re: [Nouveau] [PATCH] drm/nouveau/mmu: use struct_size() helper To: "Gustavo A. R. Silva" Cc: Ben Skeggs , David Airlie , Daniel Vetter , nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 25 May 2019 at 03:35, 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, in particular in the > context in which this code is being used. > > So, replace the following form: > > sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr; > > with: > > struct_size(kind, data, mmu->kind_nr) > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Thanks! > --- > drivers/gpu/drm/nouveau/nvif/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/nouveau/nvif/mmu.c b/drivers/gpu/drm/nouveau/nvif/mmu.c > index ae08a1ca8044..5641bda2046d 100644 > --- a/drivers/gpu/drm/nouveau/nvif/mmu.c > +++ b/drivers/gpu/drm/nouveau/nvif/mmu.c > @@ -110,7 +110,7 @@ nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu) > > if (mmu->kind_nr) { > struct nvif_mmu_kind_v0 *kind; > - u32 argc = sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr; > + size_t argc = struct_size(kind, data, mmu->kind_nr); > > if (ret = -ENOMEM, !(kind = kmalloc(argc, GFP_KERNEL))) > goto done; > -- > 2.21.0 > > _______________________________________________ > Nouveau mailing list > Nouveau@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/nouveau