Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4264252imu; Mon, 28 Jan 2019 21:27:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN5NT6UfALGVdUSiX36qeXqWjSSE8Cj66tH5EWTcxnSjdnXRpritiRaq9lDmVS3dGTX/wJj9 X-Received: by 2002:a63:2586:: with SMTP id l128mr22798368pgl.104.1548739622012; Mon, 28 Jan 2019 21:27:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548739621; cv=none; d=google.com; s=arc-20160816; b=sovLTFUUtaUHofM/fWPi+frpPXYBgnp54waIME+frLP+cykz2uXGUMVYAYeRXdRTF3 /ouB/cM/jOKTuK8rRmgWbtLw8fv/24htvvHftCfkovyq2cjJuQ51YZOapstbnJiDaBKG kEdkb0RHVTtTwqZYI6YS4Tt3Aaqg5pu04/ZVUbwZpjk6onEq9Hw9n5oaX6mCd8ecGCe2 +zUpvXmlFnKqq+Inf58QKrw+PbCbyYyQG643Y2OD5NvgUwIpm+O7a2cLIEmXct2KUFp5 ydsgZ+e/S7X6DChzpPvX0LSPKdm3Ek5+nwphM7g+wPMNZmbuyV53PI+Nkp9tSJ7+8dtp cSOw== 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=vH6trCpzaH3Y2k6uLe5RNVpinUp6tmuQF7V5r9ojHTo=; b=I/KLoBVPGQuxxyLWpI7V8/Y3KdXZ8V+u/wE/rkmE55MVFZYBbOqbylW+c7h8OJgsk0 Zpmg+Yokp+4W5KbwAZFEedQu8mwW0mEEBZCoOct6WraED/COoP08+VPC89Hg7DGz+BSV JhKzGu8Xu1iveNIouanjrgixBgeAYKfQQ4qR0EqmAhvYvNl54Eubt8Wy2KAw6Xd+Vqxt cMmFYq6XnHgfhqzbrGoAfw3gdz+yLsdWnF6DnPaV8G7ZCmcFZ7QuC8vtD/q7e7r9kDT+ dgYv80Kr84Tmwd7ZxYLoZt/CSuKcKx7pY6hKOF4qp/TpB1qakLoBiW9q7CVmlJQC9eX/ pY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=OSONzU8y; 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 u22si3390807pgk.335.2019.01.28.21.26.46; Mon, 28 Jan 2019 21:27:01 -0800 (PST) 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=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=OSONzU8y; 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 S1726198AbfA2F0W (ORCPT + 99 others); Tue, 29 Jan 2019 00:26:22 -0500 Received: from mail-vs1-f67.google.com ([209.85.217.67]:40919 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfA2F0W (ORCPT ); Tue, 29 Jan 2019 00:26:22 -0500 Received: by mail-vs1-f67.google.com with SMTP id z3so11238242vsf.7 for ; Mon, 28 Jan 2019 21:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vH6trCpzaH3Y2k6uLe5RNVpinUp6tmuQF7V5r9ojHTo=; b=OSONzU8yJ+nMk/zAj4WUxsAVCGu6N9t6lR4yeVjj8HIPjNTHRdgCEFqaG0tU/vBNTR uVB0gzFeGeuKFIX0jpB7SBaYJXX2x7nla51RPVJ16Vj006fiSTozkOY2BV2vagBFHJ3K 8MUL5KQJIo9DAj6zYjTl4iPFOXAJ6DYcsKWtcAywpgEIAG0oRqFei51b1i/CvlTc3/FT y55EhAv9qxWViW/yeBw6EPIQ76cgQcKnCRHV+tHUSPLctZVR3gJbUNRfeHWvlbQFcKX5 sp1ZZrVJw70pXUThJ9KeqAd7+sMb57dBNT0KrpwwWG5QbTrxAovvsAjs2dfx/A+pF/ST O3lA== 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=vH6trCpzaH3Y2k6uLe5RNVpinUp6tmuQF7V5r9ojHTo=; b=A8hOlHERrZ80wvcZrIWOFrmM8rLKOauiqZrZ7fulXEdnDKYiqiYOnzg9MfnZX6rs+M Im6I2sJIxoWBvk8kiC20avyw8k67pL9H9ZZyuz2C/fh6PYYHu1jtuavOcBP5gBrUlmO4 umUcOyr0tujIRXJi1PipAjAOQvUWveYp342DYCXzbaFdDetYvcnqLh3OgHZEaOac3rSC QFwfcfoNILCIlaZ0SKStg/owZUS4CRtp/VA4Z9Nx1swzp2d2yAMfBlJvLxmrpvuG4RCW hlTNVWzgpIMk4y+f4G08L9Y8VIranFrtXR76npRNx+9cEqlwZv0yZjUDs8F5QzSzUx9O FC0g== X-Gm-Message-State: AJcUukfF+Dvcd5hbovaGUBjPGJOB+gbKzv54Uiq1BSGuotPHShvZ7aSN SE94DRDTNKpf+9jX3Rcpy4zHqYM3YzfblTQ69J/30w== X-Received: by 2002:a67:e34e:: with SMTP id s14mr9958507vsm.95.1548739580811; Mon, 28 Jan 2019 21:26:20 -0800 (PST) MIME-Version: 1.0 References: <20181224062235.GA27815@embeddedor.com> In-Reply-To: <20181224062235.GA27815@embeddedor.com> From: Amit Kucheria Date: Tue, 29 Jan 2019 10:56:09 +0530 Message-ID: Subject: Re: [PATCH] drivers: qcom: rpmh: use struct_size() in kzalloc() To: "Gustavo A. R. Silva" Cc: Andy Gross , David Brown , linux-arm-msm , LKML 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 Mon, Dec 24, 2018 at 11:52 AM Gustavo A. R. Silva wrote: > > One of the more common cases of allocation size calculations is finding > the size of a structure that has a zero-sized array at the end, along > with memory for some number of elements for that array. For example: > > struct foo { > int stuff; > void *entry[]; > }; > > instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL); > > Instead of leaving these open-coded and prone to type mistakes, we can > now use the new struct_size() helper: > > instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL); > > This issue was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Reviewed-by: Amit Kucheria > --- > drivers/soc/qcom/rpmh.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c > index c7beb6841289..12c057a0b325 100644 > --- a/drivers/soc/qcom/rpmh.c > +++ b/drivers/soc/qcom/rpmh.c > @@ -362,8 +362,7 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state, > if (!count) > return -EINVAL; > > - req = kzalloc(sizeof(*req) + count * sizeof(req->rpm_msgs[0]), > - GFP_ATOMIC); > + req = kzalloc(struct_size(req, rpm_msgs, count), GFP_ATOMIC); > if (!req) > return -ENOMEM; > req->count = count; > -- > 2.17.0 >