Received: by 2002:a17:90a:2044:0:0:0:0 with SMTP id n62csp532337pjc; Mon, 20 May 2019 11:21:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiyplFG/CMQOheONOCiX5usTwftyPlvyyg8X66S+1FZXnJeXR8b0zYt8KKsbz9fRStDrt2 X-Received: by 2002:a65:44cb:: with SMTP id g11mr76646161pgs.193.1558376508927; Mon, 20 May 2019 11:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558376508; cv=none; d=google.com; s=arc-20160816; b=U5s+NoKvr6roov95ZrX4P9FHPvJAlXnTpSNAeRa7LyLT9BbTzqoWVqrUI9TjqcMcch L+/PzGQUY+XarePnyZXBDcjc32yjaKjDVhX0Ocl4BBZeVG3TRoCllbBKD9zFE6nW5d3X ZcPkbYsjdBkEegiiV9uQqwyujFX2PWfe78Sgd6IRN68SRhkFs+whKwZctnyCAak2jUU6 MeJpsIiO62MWDcX8bdWGDAKzaMpTk7cw5dA2GGF8mX6loViIZDZk9kTI6/N79l3y1Ymg PTkIfGvZJBr5ejRekUryr5HBGGNz0L2pW2Wrs8fFKirkTm0kZCa+YNbFVufwM9QCXkVG q+hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=SaB/HyT6/oED/ncLmyVItIP9zgJopLUDhT4V1Cn8C8s=; b=prtrJHOvXQ9XEuJ2sI0sgOBGt15A6waO/nal3IfjXUltDAmCcpam2XT/5BOx/xpNmj J1WvLLhdIrGiX8Pf4fC33bSGeaeDRZ+bnLGWNHNAnm/EPHhsfITcQgEUHyRxbAH6iIrq PD2lm5HQyqlTsWBgz/eqwj2W3zxggA+gEZzAU5c7mcVHutPv3H5+/EIMR6sEL+vBVprc IF9B36YuopPOwKtQC9+z8F5ntOy2RPZj7zxr9Xs+JA0SPgbYHVTXSFNknIC1Mxl5YR16 4sr4txSStJZCwFoDpXBCKgKPFoBSuxXIZt+wtBT2J9ihsXB99jx7fTWfHbZS6tsha/Uq A8ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=frcPfBLa; 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 w188si20145688pfd.204.2019.05.20.11.21.34; Mon, 20 May 2019 11:21:48 -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=frcPfBLa; 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 S2404024AbfETRlP (ORCPT + 99 others); Mon, 20 May 2019 13:41:15 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35098 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730952AbfETRlO (ORCPT ); Mon, 20 May 2019 13:41:14 -0400 Received: by mail-wr1-f67.google.com with SMTP id m3so2600712wrv.2 for ; Mon, 20 May 2019 10:41:13 -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:content-transfer-encoding; bh=SaB/HyT6/oED/ncLmyVItIP9zgJopLUDhT4V1Cn8C8s=; b=frcPfBLaCkAw55Tyx6V/dkyb1Dmt0u/f01wtgyBsyWUXbf/vOUNITWX7xPXthtq0xl bft0muUuT9iexs2vQ6DlzlFzt4voZf+LvjjC96BVra+o4/eQ/6NNFm6ml2Hf9zFy6YzE JDIAM8DK86IRqaDnt4iGFGaI10ic5qzQ4IzjI2HJBMvBq91Im9WWCtGHe/1I5MMDTDuW tNJjaUtpCSy+KGiqj8wU1HfSUfMf0FgqnY7t6aySQ/vN+w351CycwNdbRsBZbklhCeW3 PiQAyp++pVdCmkr8h/Xf6Sx/RdJ37H8FM5mDXNSTsgGvXOIsyd9IntqgI6opnb7PTlAy 1bkg== 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:content-transfer-encoding; bh=SaB/HyT6/oED/ncLmyVItIP9zgJopLUDhT4V1Cn8C8s=; b=im1JMF3e5EM+7HBYeue4mXp4rpr7zYZHrmXd587RolyN7j6mNt0xKoCACL9Sw2/bmn 1+MfC0D9YCKbziZI8OlxpAhVJZXMTUbYMrrRoYfBFhkEbZ2+vt6IkiNFavJ9KO1bwfCV 5F39FN7huMtfS3erDiGG9NbhzHdMVGtTFLEJNT9PSECogT5lhMqDCn+kH7k8VFIx+nir hkc4ubNhpvjkeA0xP/4Xk7WVmwwk1r+QlKN8G+hf11CWTUhqXyUnRVoXvGfmZ/Z/yXr3 NAJFiqHWBI/T0yQw//3pRa9W1artkD0kDK/YX8baBmOz9UBeaDv94GAZXsPrBcVuVTBz wWJg== X-Gm-Message-State: APjAAAVIIZ8QtUzIKiAUGnorzMF1+6AsRHLE4JyqsZ8GRgmGhFLxfkSn cr++Sq2u3044GLG4khfsvjBGYKDGk2HmzC3xucY= X-Received: by 2002:adf:8bc5:: with SMTP id w5mr3818759wra.132.1558374073011; Mon, 20 May 2019 10:41:13 -0700 (PDT) MIME-Version: 1.0 References: <1558082760-4915-1-git-send-email-xiaolinkui@kylinos.cn> In-Reply-To: <1558082760-4915-1-git-send-email-xiaolinkui@kylinos.cn> From: Alex Deucher Date: Mon, 20 May 2019 13:41:00 -0400 Message-ID: Subject: Re: [PATCH] gpu: drm: use struct_size() in kmalloc() To: xiaolinkui Cc: "Deucher, Alexander" , Christian Koenig , Chunming Zhou , Dave Airlie , Daniel Vetter , xinhui pan , "Quan, Evan" , Maling list - DRI developers , amd-gfx list , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 17, 2019 at 8:43 AM xiaolinkui wrote: > > Use struct_size() helper to keep code simple. > > Signed-off-by: xiaolinkui > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) This patch results in the following build error: DESCEND objtool CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC [M] drivers/gpu/drm/amd/amdgpu/amdgpu_ras.o In file included from ./include/linux/kernel.h:15, from ./include/linux/list.h:9, from ./include/linux/wait.h:7, from ./include/linux/wait_bit.h:8, from ./include/linux/fs.h:6, from ./include/linux/debugfs.h:15, from drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:24: drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c: In function =E2=80=98amdgpu_ras_in= it=E2=80=99: ./include/linux/build_bug.h:16:45: error: negative width in bit-field =E2=80=98=E2=80=99 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ ./include/linux/compiler.h:349:28: note: in expansion of macro =E2=80=98BUILD_BUG_ON_ZERO=E2=80=99 #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) ^~~~~~~~~~~~~~~~~ ./include/linux/overflow.h:306:30: note: in expansion of macro =E2=80=98__m= ust_be_array=E2=80=99 sizeof(*(p)->member) + __must_be_array((p)->member),\ ^~~~~~~~~~~~~~~ drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1556:16: note: in expansion of macro =E2=80=98struct_size=E2=80=99 con =3D kmalloc(struct_size(con, objs, AMDGPU_RAS_BLOCK_COUNT), ^~~~~~~~~~~ make[4]: *** [scripts/Makefile.build:276: drivers/gpu/drm/amd/amdgpu/amdgpu_ras.o] Error 1 make[4]: *** Waiting for unfinished jobs.... make[3]: *** [scripts/Makefile.build:492: drivers/gpu/drm/amd/amdgpu] Error= 2 make[3]: *** Waiting for unfinished jobs.... make[2]: *** [scripts/Makefile.build:492: drivers/gpu/drm] Error 2 make[1]: *** [scripts/Makefile.build:492: drivers/gpu] Error 2 make: *** [Makefile:1042: drivers] Error 2 Alex > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/am= d/amdgpu/amdgpu_ras.c > index 22bd21e..4717a64 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c > @@ -1375,8 +1375,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev) > if (con) > return 0; > > - con =3D kmalloc(sizeof(struct amdgpu_ras) + > - sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COU= NT, > + con =3D kmalloc(struct_size(con, objs, AMDGPU_RAS_BLOCK_COUNT), > GFP_KERNEL|__GFP_ZERO); > if (!con) > return -ENOMEM; > -- > 2.7.4 > > > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx