mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>,
	linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH][next] bcache: Use struct_size() in kzalloc()
Date: Thu, 18 Jun 2020 13:38:08 +0800	[thread overview]
Message-ID: <1c6adee3-bbad-dc88-3dd2-af823f279271@suse.de> (raw)
In-Reply-To: <20200617222733.GA24156@embeddedor>

On 2020/6/18 06:27, 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.
> 
> 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/md/bcache/writeback.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
> index 1cf1e5016cb9..c0db3c860179 100644
> --- a/drivers/md/bcache/writeback.c
> +++ b/drivers/md/bcache/writeback.c
> @@ -459,10 +459,8 @@ static void read_dirty(struct cached_dev *dc)
>  		for (i = 0; i < nk; i++) {
>  			w = keys[i];
>  
> -			io = kzalloc(sizeof(struct dirty_io) +
> -				     sizeof(struct bio_vec) *
> -				     DIV_ROUND_UP(KEY_SIZE(&w->key),
> -						  PAGE_SECTORS),
> +			io = kzalloc(struct_size(io, bio.bi_inline_vecs,
                                                     ^^^^^^^^^^^^^^^^^^
                                                     I like this :-)

> +						DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS)),

The above line seems too long for 80 characters limitation. Does
checkpatch.pl complain for this ?


Thanks.

Coly Li


>  				     GFP_KERNEL);
>  			if (!io)
>  				goto err;
> 


  reply	other threads:[~2020-06-18  5:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 22:27 Gustavo A. R. Silva
2020-06-18  5:38 ` Coly Li [this message]
2020-06-18  5:42   ` Joe Perches
2020-06-19 15:01     ` Coly Li

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=1c6adee3-bbad-dc88-3dd2-af823f279271@suse.de \
    --to=colyli@suse.de \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@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

all inboxes | Powered by JetHome®