linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Moritz Fischer <mdf@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Wu Hao <hao.wu@intel.com>, Moritz Fischer <mdf@kernel.org>,
	linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH][next] fpga: dfl: Use struct_size() in kzalloc()
Date: Thu, 18 Jun 2020 18:40:38 -0700	[thread overview]
Message-ID: <20200619014036.GF3685@epycbox.lan> (raw)
In-Reply-To: <20200617221039.GA21877@embeddedor>

On Wed, Jun 17, 2020 at 05:10:39PM -0500, 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. Also, remove unnecessary
> function dfl_feature_platform_data_size().
> 
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/fpga/dfl.c | 3 +--
>  drivers/fpga/dfl.h | 6 ------
>  2 files changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 990994874bf1..2dd13e036d45 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -487,8 +487,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  	 * it will be automatically freed by device's release() callback,
>  	 * platform_device_release().
>  	 */
> -	pdata = kzalloc(dfl_feature_platform_data_size(binfo->feature_num),
> -			GFP_KERNEL);
> +	pdata = kzalloc(struct_size(pdata, features, binfo->feature_num), GFP_KERNEL);
>  	if (!pdata)
>  		return -ENOMEM;
>  
> diff --git a/drivers/fpga/dfl.h b/drivers/fpga/dfl.h
> index 2f5d3052e36e..044b0e88e5a8 100644
> --- a/drivers/fpga/dfl.h
> +++ b/drivers/fpga/dfl.h
> @@ -299,12 +299,6 @@ struct dfl_feature_ops {
>  #define DFL_FPGA_FEATURE_DEV_FME		"dfl-fme"
>  #define DFL_FPGA_FEATURE_DEV_PORT		"dfl-port"
>  
> -static inline int dfl_feature_platform_data_size(const int num)
> -{
> -	return sizeof(struct dfl_feature_platform_data) +
> -		num * sizeof(struct dfl_feature);
> -}
> -
>  void dfl_fpga_dev_feature_uinit(struct platform_device *pdev);
>  int dfl_fpga_dev_feature_init(struct platform_device *pdev,
>  			      struct dfl_feature_driver *feature_drvs);
> -- 
> 2.27.0
> 
Applied to for-next,

Thanks!

      reply	other threads:[~2020-06-19  1:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 22:10 [PATCH][next] fpga: dfl: Use struct_size() in kzalloc() Gustavo A. R. Silva
2020-06-19  1:40 ` Moritz Fischer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200619014036.GF3685@epycbox.lan \
    --to=mdf@kernel.org \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=hao.wu@intel.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).