alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Jérémy Lefaure" <jeremy.lefaure@lse.epita.fr>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/18] sound: use ARRAY_SIZE
Date: Sun, 01 Oct 2017 21:16:19 -0700	[thread overview]
Message-ID: <1506917779.2274.9.camel@perches.com> (raw)
In-Reply-To: <20171001193101.8898-2-jeremy.lefaure@lse.epita.fr>

On Sun, 2017-10-01 at 15:30 -0400, Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code.
> 
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> > 
> 
>  (sizeof(E)@p /sizeof(E[...]))
> > 
> 
>  (sizeof(E)@p /sizeof(T))
> )
[]
> diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
[]
> @@ -797,7 +798,7 @@ static int ad1848_set_speed(int dev, int arg)
>  
>  	int i, n, selected = -1;
>  
> -	n = sizeof(speed_table) / sizeof(speed_struct);
> +	n = ARRAY_SIZE(speed_table);

These sorts of changes are OK, but for many
uses, it's more readable to use ARRAY_SIZE(foo)
in each location rather than using a temporary.

  reply	other threads:[~2017-10-02  4:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-01 19:30 [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure
2017-10-01 19:30 ` [PATCH 01/18] sound: use ARRAY_SIZE Jérémy Lefaure
2017-10-02  4:16   ` Joe Perches [this message]
2017-10-03  1:12     ` Jérémy Lefaure
2017-10-03  7:03   ` Takashi Iwai
2017-10-01 22:01 ` [PATCH 00/18] use ARRAY_SIZE macro Tobin C. Harding
2017-10-02  0:52   ` Jérémy Lefaure
2017-10-02  5:35     ` Greg KH
2017-10-02 19:22       ` J. Bruce Fields
2017-10-03  1:33         ` Jérémy Lefaure
2017-10-05 17:57           ` J. Bruce Fields
2017-10-02 16:37     ` Mauro Carvalho Chehab
2017-10-02 17:05 ` Zhi Wang

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=1506917779.2274.9.camel@perches.com \
    --to=joe@perches.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=jeremy.lefaure@lse.epita.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /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).