Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp631363ybm; Tue, 21 May 2019 00:26:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5f5JbiD8mvz58dnn0vyIF5qw3pisJFp5f0zI34z6cVH6SLUlq0iXEZ1j1+z6URGBz4t9G X-Received: by 2002:a63:8dc9:: with SMTP id z192mr35082586pgd.6.1558423566762; Tue, 21 May 2019 00:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558423566; cv=none; d=google.com; s=arc-20160816; b=p44OKjTeCptDeO90gXnS9gR342LdplMsWdq3wOgPYeWbYAsYXpt4YDF4jUC0RUyLAK IAxG8H/8AjoM40p89vW5apzVVAZv02PM/4Bc8jirgXZ4u6b54K9hzHuQ+rxfX2qmyo2i BDVFyVTDJqsMHqg7HyyrJCVGH84W7/m+HncWB3GPgAc+fAyZjU9A1jKaQ/RPCcr0nsQu NcGc8S7tUoAUoU2pKqG+G+qDWCBqOeB5xYbPiV1V0PACeTpAVgYE88lQbdNlmMiyf/+B o4oyxkMprPkE2kaGHdCoFoibZfVfr7b08Ynn9MTOAf+XLlhnNpIqBILa5CK2lMLKrjtM 5MFQ== 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=DPQL8bz6Ge/eFLfJPuBWgxB/nSLqSz43ISfLIGw+Rn0=; b=UQbdokMCW+SqLCrFxXgiFStjQ9YJ6qyZNKN+aBOujJ31bi69coVgYTbxiSdL8/kgY2 fthXZiBotUlOZWoKprizzimYCxygDOLwYCz1oRHxDtrJLOAb2ihEu7te7tu4GYwfpk6P Ir8Z72bGef9Xffgvsc9vF3rqg9245rj848wGfI8J6GZyLJCvm0VtCmCh2SvC6gOhHXO3 nQEJ1IQRRnoKLA0YViJUcNy8JIPecqlU2pWuM94ednHqY0MjwfbLp3gUH2y3bh3HQ7Ni qHqs5G3sBPrigNWhqPj9GUA8uU54bSJK6NM3ap8SyTZPWpyM+zKpZ9fIpxoi4Rx2MYll xDmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=RttiH3G6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e63si12460793pgc.340.2019.05.21.00.25.51; Tue, 21 May 2019 00:26:06 -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=@ffwll.ch header.s=google header.b=RttiH3G6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726753AbfEUHX2 (ORCPT + 99 others); Tue, 21 May 2019 03:23:28 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:40341 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726011AbfEUHX1 (ORCPT ); Tue, 21 May 2019 03:23:27 -0400 Received: by mail-ot1-f68.google.com with SMTP id u11so15400946otq.7 for ; Tue, 21 May 2019 00:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DPQL8bz6Ge/eFLfJPuBWgxB/nSLqSz43ISfLIGw+Rn0=; b=RttiH3G67ThRjHMOpk4pcVI/VMZPc5TF2PsMtvOI1PMokcZqYS7EectW/z54H7FqiF ovukQ8zGr07qzNzAkQ482SUGOCpjq8+PKUV7PJmRe2njXqsuR3SkafzFpr77LyQTCbZD k3FpSMJ2zRic7PUIm4ogcRJ3+3tTAO/e1CK/w= 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=DPQL8bz6Ge/eFLfJPuBWgxB/nSLqSz43ISfLIGw+Rn0=; b=qWRq4TCg2AFhzKARKv6/phuckwdnW/kBYlAB4SmUmLu8uohz5qlTU5nbFhhOQtH3Ep mTs3qeL4MGvkKjESCW8lRdmrVGCKrqRikuFYMKIUXVnAxRoTzAVxClKZUwpDGFkRvxO9 sRRmMIe/iHqFmVBrFQiVVxXi5d+JwcfKTE45ICoG9cSoNA26blNTjEId8CPalZUxIwtI IAickqzZneAB+JDS62iKobq5wTR/59Fcc/d6/51RE4i6mN2jD6WSFBX/zhAVUXqOcmkl N0ELhiSNEd45RHrj1hRE4maoGzKZsRIrL+R9pNNqMWEd1v17L8oOOPobS5TkRCpL3rg7 Iolg== X-Gm-Message-State: APjAAAX1ogWZonD+cEa6UuQjXU8diuA93NMGEe7Zs8zc+rXMcJR7LKRv 1XlWhcQllCmmiXxZiyG9Cb0uK/ILyRPwoqq/1CZslDzCViY= X-Received: by 2002:a9d:7395:: with SMTP id j21mr2061299otk.204.1558423406551; Tue, 21 May 2019 00:23:26 -0700 (PDT) MIME-Version: 1.0 References: <1558082760-4915-1-git-send-email-xiaolinkui@kylinos.cn> <20190520162807.GE21222@phenom.ffwll.local> In-Reply-To: From: Daniel Vetter Date: Tue, 21 May 2019 09:23:14 +0200 Message-ID: Subject: Re: [PATCH] gpu: drm: use struct_size() in kmalloc() To: Alex Deucher Cc: "Pan, Xinhui" , "Zhou, David(ChunMing)" , "airlied@linux.ie" , xiaolinkui , "linux-kernel@vger.kernel.org" , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "Deucher, Alexander" , "Quan, Evan" , "Koenig, Christian" 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 Tue, May 21, 2019 at 4:33 AM Alex Deucher wrote: > > On Mon, May 20, 2019 at 7:19 PM Pan, Xinhui wrote: > > > > Daniel, what you are talking about is totally wrong. > > 1) AFAIK, only one zero-size array can be in the end of a struct. > > 2) two struct_size will add up struct itself twice. the sum is wrong th= en. > > > > No offense. I can't help feeling lucky that you are in intel. > > Xinhui, > > Please keep things civil. There is no need for comments like this. Yeah, this was over the line, thanks Alex for already taking care of this. Please note that fd.o mailing lists operate under a CoC: https://www.freedesktop.org/wiki/CodeOfConduct/ Wrt the technical comment: I know that you can only do one variable sized array, and it must be at the end. But you can put multiple structures all within the same allocation. Which is what I thought you wanted to do. And my sketch would allow you to do that even if you have multiple variable length structures you want to allocate. There's plenty examples of this (but open-coded ones) in the kernel. Except in really hot paths I personally think that that kind of trickery isn't worth it. Cheers, Daniel > > Alex > > > > > > > =E5=8F=91=E4=BB=B6=E4=BA=BA: Daniel Vetter =E4= =BB=A3=E8=A1=A8 Daniel Vetter > > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2019=E5=B9=B45=E6=9C=8821=E6=97= =A5 0:28 > > =E6=94=B6=E4=BB=B6=E4=BA=BA: Pan, Xinhui > > =E6=8A=84=E9=80=81: Deucher, Alexander; Koenig, Christian; Zhou, David(= ChunMing); airlied@linux.ie; daniel@ffwll.ch; Quan, Evan; xiaolinkui; amd-g= fx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-kernel@vge= r.kernel.org > > =E4=B8=BB=E9=A2=98: Re: [PATCH] gpu: drm: use struct_size() in kmalloc(= ) > > > > [CAUTION: External Email] > > > > On Fri, May 17, 2019 at 04:44:30PM +0000, Pan, Xinhui wrote: > > > I am going to put more members which are also array after this struct= , > > > not only obj[]. Looks like this struct_size did not help on multiple > > > array case. Thanks anyway. ________________________________ > > > > You can then add them up, e.g. kmalloc(struct_size()+struct_size(), > > GFP_KERNEL), so this patch here still looks like a good idea. > > > > Reviewed-by: Daniel Vetter > > > > Cheers, Daniel > > > > > From: xiaolinkui > > > Sent: Friday, May 17, 2019 4:46:00 PM > > > To: Deucher, Alexander; Koenig, Christian; Zhou, David(ChunMing); air= lied@linux.ie; daniel@ffwll.ch; Pan, Xinhui; Quan, Evan > > > Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; l= inux-kernel@vger.kernel.org; xiaolinkui@kylinos.cn > > > Subject: [PATCH] gpu: drm: use struct_size() in kmalloc() > > > > > > [CAUTION: External Email] > > > > > > 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(-) > > > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/dr= m/amd/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= _COUNT, > > > + con =3D kmalloc(struct_size(con, objs, AMDGPU_RAS_BLOCK_COUNT= ), > > > GFP_KERNEL|__GFP_ZERO); > > > if (!con) > > > return -ENOMEM; > > > -- > > > 2.7.4 > > > > > > > > > > > > > -- > > Daniel Vetter > > Software Engineer, Intel Corporation > > http://blog.ffwll.ch > > _______________________________________________ > > amd-gfx mailing list > > amd-gfx@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/amd-gfx --=20 Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch