linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/18] use ARRAY_SIZE macro
@ 2017-10-01 19:30 Jérémy Lefaure
  2017-10-01 19:30 ` [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jérémy Lefaure @ 2017-10-01 19:30 UTC (permalink / raw)
  Cc: alsa-devel, amd-gfx, brcm80211-dev-list, brcm80211-dev-list.pdl,
	devel, devel, dm-devel, dri-devel, ecryptfs, intel-gfx,
	intel-gvt-dev, intel-wired-lan, Jason Gunthorpe, linux-acpi,
	linux-integrity, linux-kernel, linux-media, linux-nfs, linux-raid,
	linux-rdma, linux-scsi, linux-usb, linux-video, linux-wireless,
	netdev, nouveau, openipmi-developer

Hi everyone,
Using ARRAY_SIZE improves the code readability. I used coccinelle (I
made a change to the array_size.cocci file [1]) to find several places
where ARRAY_SIZE could be used instead of other macros or sizeof
division.

I tried to divide the changes into a patch per subsystem (excepted for
staging). If one of the patch should be split into several patches, let
me know.

In order to reduce the size of the To: and Cc: lines, each patch of the
series is sent only to the maintainers and lists concerned by the patch.
This cover letter is sent to every list concerned by this series.

This series is based on linux-next next-20170929. Each patch has been
tested by building the relevant files with W=1.

This series contains the following patches:
[PATCH 01/18] sound: use ARRAY_SIZE
[PATCH 02/18] tracing/filter: use ARRAY_SIZE
[PATCH 03/18] media: use ARRAY_SIZE
[PATCH 04/18] IB/mlx5: Use ARRAY_SIZE
[PATCH 05/18] net: use ARRAY_SIZE
[PATCH 06/18] drm: use ARRAY_SIZE
[PATCH 07/18] scsi: bfa: use ARRAY_SIZE
[PATCH 08/18] ecryptfs: use ARRAY_SIZE
[PATCH 09/18] nfsd: use ARRAY_SIZE
[PATCH 10/18] orangefs: use ARRAY_SIZE
[PATCH 11/18] dm space map metadata: use ARRAY_SIZE
[PATCH 12/18] x86: use ARRAY_SIZE
[PATCH 13/18] tpm: use ARRAY_SIZE
[PATCH 14/18] ipmi: use ARRAY_SIZE
[PATCH 15/18] acpi: use ARRAY_SIZE
[PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE
[PATCH 17/18] staging: rtl8723bs: use ARRAY_SIZE
[PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE


[1]: https://lkml.org/lkml/2017/9/13/689

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 03/18] media: use ARRAY_SIZE
  2017-10-01 19:30 [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure
@ 2017-10-01 19:30 ` Jérémy Lefaure
  2017-10-02 10:34   ` Michael Ira Krufky
  2017-10-01 19:30 ` [PATCH 16/18] media: staging: atomisp: " Jérémy Lefaure
  2017-10-01 22:01 ` [PATCH 00/18] use ARRAY_SIZE macro Tobin C. Harding
  2 siblings, 1 reply; 11+ messages in thread
From: Jérémy Lefaure @ 2017-10-01 19:30 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab, Sergey Kozlov, Abylay Ospan,
	Michael Krufky
  Cc: Jérémy Lefaure, linux-media, linux-kernel

Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is not always useful to use a variable to store this constant
calculated at compile time.

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))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/media/common/saa7146/saa7146_video.c | 9 ++++-----
 drivers/media/dvb-frontends/cxd2841er.c      | 7 +++----
 drivers/media/pci/saa7146/hexium_gemini.c    | 3 ++-
 drivers/media/pci/saa7146/hexium_orion.c     | 3 ++-
 drivers/media/pci/saa7146/mxb.c              | 3 ++-
 drivers/media/usb/dvb-usb/cxusb.c            | 3 ++-
 drivers/media/usb/dvb-usb/friio-fe.c         | 5 ++---
 7 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index 37b4654dc21c..612aefd804f0 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -4,6 +4,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-ctrls.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int max_memory = 32;
 
@@ -86,13 +87,11 @@ static struct saa7146_format formats[] = {
    due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped
    (like V4L2_PIX_FMT_YUYV) ... 8-( */
 
-static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format);
-
 struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc)
 {
-	int i, j = NUM_FORMATS;
+	int i;
 
-	for (i = 0; i < j; i++) {
+	for (i = 0; i < ARRAY_SIZE(formats); i++) {
 		if (formats[i].pixelformat == fourcc) {
 			return formats+i;
 		}
@@ -524,7 +523,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuf
 
 static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
 {
-	if (f->index >= NUM_FORMATS)
+	if (f->index >= ARRAY_SIZE(formats))
 		return -EINVAL;
 	strlcpy((char *)f->description, formats[f->index].name,
 			sizeof(f->description));
diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c
index 48ee9bc00c06..2cb97a3130be 100644
--- a/drivers/media/dvb-frontends/cxd2841er.c
+++ b/drivers/media/dvb-frontends/cxd2841er.c
@@ -29,6 +29,7 @@
 #include <linux/math64.h>
 #include <linux/log2.h>
 #include <linux/dynamic_debug.h>
+#include <linux/kernel.h>
 
 #include "dvb_math.h"
 #include "dvb_frontend.h"
@@ -1696,12 +1697,10 @@ static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
 		min_index = 0;
 		if (delsys == SYS_DVBS) {
 			cn_data = s_cn_data;
-			max_index = sizeof(s_cn_data) /
-				sizeof(s_cn_data[0]) - 1;
+			max_index = ARRAY_SIZE(s_cn_data) - 1;
 		} else {
 			cn_data = s2_cn_data;
-			max_index = sizeof(s2_cn_data) /
-				sizeof(s2_cn_data[0]) - 1;
+			max_index = ARRAY_SIZE(s2_cn_data) - 1;
 		}
 		if (value >= cn_data[min_index].value) {
 			res = cn_data[min_index].cnr_x1000;
diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
index d31a2d4494d1..39357eddee32 100644
--- a/drivers/media/pci/saa7146/hexium_gemini.c
+++ b/drivers/media/pci/saa7146/hexium_gemini.c
@@ -27,6 +27,7 @@
 
 #include <media/drv-intf/saa7146_vv.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int debug;
 module_param(debug, int, 0);
@@ -388,7 +389,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs = HEXIUM_INPUTS,
 	.capabilities = 0,
 	.stds = &hexium_standards[0],
-	.num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+	.num_stds = ARRAY_SIZE(hexium_standards),
 	.std_callback = &std_callback,
 };
 
diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
index 043318aa19e2..461e421080f3 100644
--- a/drivers/media/pci/saa7146/hexium_orion.c
+++ b/drivers/media/pci/saa7146/hexium_orion.c
@@ -27,6 +27,7 @@
 
 #include <media/drv-intf/saa7146_vv.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int debug;
 module_param(debug, int, 0);
@@ -460,7 +461,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs = HEXIUM_INPUTS,
 	.capabilities = 0,
 	.stds = &hexium_standards[0],
-	.num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+	.num_stds = ARRAY_SIZE(hexium_standards),
 	.std_callback = &std_callback,
 };
 
diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
index 930218cc2de1..0144f305ea24 100644
--- a/drivers/media/pci/saa7146/mxb.c
+++ b/drivers/media/pci/saa7146/mxb.c
@@ -30,6 +30,7 @@
 #include <media/v4l2-common.h>
 #include <media/i2c/saa7115.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 #include "tea6415c.h"
 #include "tea6420.h"
@@ -837,7 +838,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs		= MXB_INPUTS,
 	.capabilities	= V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
 	.stds		= &standard[0],
-	.num_stds	= sizeof(standard)/sizeof(struct saa7146_standard),
+	.num_stds	= ARRAY_SIZE(standard),
 	.std_callback	= &std_callback,
 };
 
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index 37dea0adc695..9b486bb5004d 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -26,6 +26,7 @@
 #include <media/tuner.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 #include "cxusb.h"
 
@@ -303,7 +304,7 @@ static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
 			0x0e, 0x2, 0x47, 0x88,
 		};
 		msleep(20);
-		for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
+		for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
 			ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
 					     bufs+i, 4, &buf, 1);
 			if (ret)
diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
index 0251a4e91d47..a6c84a4390d1 100644
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ b/drivers/media/usb/dvb-usb/friio-fe.c
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 #include "friio.h"
 
@@ -362,8 +363,6 @@ static u8 init_code[][2] = {
 	{0x76, 0x0C},
 };
 
-static const int init_code_len = sizeof(init_code) / sizeof(u8[2]);
-
 static int jdvbt90502_init(struct dvb_frontend *fe)
 {
 	int i = -1;
@@ -377,7 +376,7 @@ static int jdvbt90502_init(struct dvb_frontend *fe)
 	msg.addr = state->config.demod_address;
 	msg.flags = 0;
 	msg.len = 2;
-	for (i = 0; i < init_code_len; i++) {
+	for (i = 0; i < ARRAY_SIZE(init_code); i++) {
 		msg.buf = init_code[i];
 		ret = i2c_transfer(state->i2c, &msg, 1);
 		if (ret != 1)
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE
  2017-10-01 19:30 [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure
  2017-10-01 19:30 ` [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure
@ 2017-10-01 19:30 ` Jérémy Lefaure
  2017-10-01 22:01 ` [PATCH 00/18] use ARRAY_SIZE macro Tobin C. Harding
  2 siblings, 0 replies; 11+ messages in thread
From: Jérémy Lefaure @ 2017-10-01 19:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Jérémy Lefaure, linux-media, devel, linux-kernel

Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to use a variable to store this constant calculated at
compile time.

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))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 .../pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c       | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
index 17d3b7de93ba..98a2a3e9b3e6 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
@@ -22,6 +22,7 @@
 #include <assert_support.h>
 /* HRT_GDC_N */
 #include "gdc_device.h"
+#include <linux/kernel.h>
 
 /* This module provides a binary descriptions to used to find a binary. Since,
  * every stage is associated with a binary, it implicity helps stage
@@ -147,11 +148,9 @@ enum ia_css_err sh_css_bds_factor_get_numerator_denominator(
 	unsigned int *bds_factor_denominator)
 {
 	unsigned int i;
-	unsigned int bds_list_size = sizeof(bds_factors_list) /
-				sizeof(struct sh_css_bds_factor);
 
 	/* Loop over all bds factors until a match is found */
-	for (i = 0; i < bds_list_size; i++) {
+	for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) {
 		if (bds_factors_list[i].bds_factor == bds_factor) {
 			*bds_factor_numerator = bds_factors_list[i].numerator;
 			*bds_factor_denominator = bds_factors_list[i].denominator;
@@ -170,8 +169,6 @@ enum ia_css_err binarydesc_calculate_bds_factor(
 	unsigned int *bds_factor)
 {
 	unsigned int i;
-	unsigned int bds_list_size = sizeof(bds_factors_list) /
-	    sizeof(struct sh_css_bds_factor);
 	unsigned int in_w = input_res.width,
 	    in_h = input_res.height,
 	    out_w = output_res.width, out_h = output_res.height;
@@ -186,7 +183,7 @@ enum ia_css_err binarydesc_calculate_bds_factor(
 	assert(out_w != 0 && out_h != 0);
 
 	/* Loop over all bds factors until a match is found */
-	for (i = 0; i < bds_list_size; i++) {
+	for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) {
 		unsigned num = bds_factors_list[i].numerator;
 		unsigned den = bds_factors_list[i].denominator;
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  2017-10-01 19:30 [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure
  2017-10-01 19:30 ` [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure
  2017-10-01 19:30 ` [PATCH 16/18] media: staging: atomisp: " Jérémy Lefaure
@ 2017-10-01 22:01 ` Tobin C. Harding
  2017-10-02  0:52   ` Jérémy Lefaure
  2 siblings, 1 reply; 11+ messages in thread
From: Tobin C. Harding @ 2017-10-01 22:01 UTC (permalink / raw)
  To: Jérémy Lefaure
  Cc: alsa-devel, nouveau, dri-devel, dm-devel, brcm80211-dev-list,
	devel, linux-scsi, linux-rdma, amd-gfx, Jason Gunthorpe,
	linux-acpi, linux-video, intel-wired-lan, linux-media, intel-gfx,
	ecryptfs, linux-nfs, linux-raid, openipmi-developer,
	intel-gvt-dev, devel, brcm80211-dev-list.pdl, netdev, linux-usb,
	linux-wireless, linux-kernel, linux-integrity

On Sun, Oct 01, 2017 at 03:30:38PM -0400, Jérémy Lefaure wrote:
> Hi everyone,
> Using ARRAY_SIZE improves the code readability. I used coccinelle (I
> made a change to the array_size.cocci file [1]) to find several places
> where ARRAY_SIZE could be used instead of other macros or sizeof
> division.
> 
> I tried to divide the changes into a patch per subsystem (excepted for
> staging). If one of the patch should be split into several patches, let
> me know.
> 
> In order to reduce the size of the To: and Cc: lines, each patch of the
> series is sent only to the maintainers and lists concerned by the patch.
> This cover letter is sent to every list concerned by this series.

Why don't you just send individual patches for each subsystem? I'm not a maintainer but I don't see
how any one person is going to be able to apply this whole series, it is making it hard for
maintainers if they have to pick patches out from among the series (if indeed any will bother
doing that).

I get that this will be more work for you but AFAIK we are optimizing for maintainers.

Good luck,
Tobin.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  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 16:37     ` Mauro Carvalho Chehab
  0 siblings, 2 replies; 11+ messages in thread
From: Jérémy Lefaure @ 2017-10-02  0:52 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: alsa-devel, nouveau, dri-devel, dm-devel, brcm80211-dev-list,
	devel, linux-scsi, linux-rdma, amd-gfx, Jason Gunthorpe,
	linux-acpi, linux-video, intel-wired-lan, linux-media, intel-gfx,
	ecryptfs, linux-nfs, linux-raid, openipmi-developer,
	intel-gvt-dev, devel, brcm80211-dev-list.pdl, netdev, linux-usb,
	linux-wireless, linux-kernel, linux-integrity

On Mon, 2 Oct 2017 09:01:31 +1100
"Tobin C. Harding" <me@tobin.cc> wrote:

> > In order to reduce the size of the To: and Cc: lines, each patch of the
> > series is sent only to the maintainers and lists concerned by the patch.
> > This cover letter is sent to every list concerned by this series.  
> 
> Why don't you just send individual patches for each subsystem? I'm not a maintainer but I don't see
> how any one person is going to be able to apply this whole series, it is making it hard for
> maintainers if they have to pick patches out from among the series (if indeed any will bother
> doing that).
Yeah, maybe it would have been better to send individual patches.

>From my point of view it's a series because the patches are related (I
did a git format-patch from my local branch). But for the maintainers
point of view, they are individual patches.

As each patch in this series is standalone, the maintainers can pick
the patches they want and apply them individually. So yeah, maybe I
should have sent individual patches. But I also wanted to tie all
patches together as it's the same change.

Anyway, I can tell to each maintainer that they can apply the patches
they're concerned about and next time I may send individual patches.

Thank you for your answer,
Jérémy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  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-02 16:37     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2017-10-02  5:35 UTC (permalink / raw)
  To: Jérémy Lefaure
  Cc: Tobin C. Harding, alsa-devel, nouveau, dri-devel, dm-devel,
	brcm80211-dev-list, devel, linux-scsi, linux-rdma, amd-gfx,
	Jason Gunthorpe, linux-acpi, linux-video, intel-wired-lan,
	linux-media, intel-gfx, ecryptfs, linux-nfs, linux-raid,
	openipmi-developer, intel-gvt-dev, devel, brcm80211-dev-list.pdl,
	netdev, linux-usb, linux-wireless, linux-kernel, linux-integrity

On Sun, Oct 01, 2017 at 08:52:20PM -0400, Jérémy Lefaure wrote:
> On Mon, 2 Oct 2017 09:01:31 +1100
> "Tobin C. Harding" <me@tobin.cc> wrote:
> 
> > > In order to reduce the size of the To: and Cc: lines, each patch of the
> > > series is sent only to the maintainers and lists concerned by the patch.
> > > This cover letter is sent to every list concerned by this series.  
> > 
> > Why don't you just send individual patches for each subsystem? I'm not a maintainer but I don't see
> > how any one person is going to be able to apply this whole series, it is making it hard for
> > maintainers if they have to pick patches out from among the series (if indeed any will bother
> > doing that).
> Yeah, maybe it would have been better to send individual patches.
> 
> From my point of view it's a series because the patches are related (I
> did a git format-patch from my local branch). But for the maintainers
> point of view, they are individual patches.

And the maintainers view is what matters here, if you wish to get your
patches reviewed and accepted...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 03/18] media: use ARRAY_SIZE
  2017-10-01 19:30 ` [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure
@ 2017-10-02 10:34   ` Michael Ira Krufky
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Ira Krufky @ 2017-10-02 10:34 UTC (permalink / raw)
  To: Jérémy Lefaure
  Cc: Hans Verkuil, Mauro Carvalho Chehab, Sergey Kozlov, Abylay Ospan,
	linux-media, LKML

On Sun, Oct 1, 2017 at 3:30 PM, Jérémy Lefaure
<jeremy.lefaure@lse.epita.fr> wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it is not always useful to use a variable to store this constant
> calculated at compile time.
>
> 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))
> )
>
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>


Reviewed-by: Michael Ira Krufky <mkrufky@linuxtv.org>


> ---
>  drivers/media/common/saa7146/saa7146_video.c | 9 ++++-----
>  drivers/media/dvb-frontends/cxd2841er.c      | 7 +++----
>  drivers/media/pci/saa7146/hexium_gemini.c    | 3 ++-
>  drivers/media/pci/saa7146/hexium_orion.c     | 3 ++-
>  drivers/media/pci/saa7146/mxb.c              | 3 ++-
>  drivers/media/usb/dvb-usb/cxusb.c            | 3 ++-
>  drivers/media/usb/dvb-usb/friio-fe.c         | 5 ++---
>  7 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
> index 37b4654dc21c..612aefd804f0 100644
> --- a/drivers/media/common/saa7146/saa7146_video.c
> +++ b/drivers/media/common/saa7146/saa7146_video.c
> @@ -4,6 +4,7 @@
>  #include <media/v4l2-event.h>
>  #include <media/v4l2-ctrls.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int max_memory = 32;
>
> @@ -86,13 +87,11 @@ static struct saa7146_format formats[] = {
>     due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped
>     (like V4L2_PIX_FMT_YUYV) ... 8-( */
>
> -static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format);
> -
>  struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc)
>  {
> -       int i, j = NUM_FORMATS;
> +       int i;
>
> -       for (i = 0; i < j; i++) {
> +       for (i = 0; i < ARRAY_SIZE(formats); i++) {
>                 if (formats[i].pixelformat == fourcc) {
>                         return formats+i;
>                 }
> @@ -524,7 +523,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuf
>
>  static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
>  {
> -       if (f->index >= NUM_FORMATS)
> +       if (f->index >= ARRAY_SIZE(formats))
>                 return -EINVAL;
>         strlcpy((char *)f->description, formats[f->index].name,
>                         sizeof(f->description));
> diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c
> index 48ee9bc00c06..2cb97a3130be 100644
> --- a/drivers/media/dvb-frontends/cxd2841er.c
> +++ b/drivers/media/dvb-frontends/cxd2841er.c
> @@ -29,6 +29,7 @@
>  #include <linux/math64.h>
>  #include <linux/log2.h>
>  #include <linux/dynamic_debug.h>
> +#include <linux/kernel.h>
>
>  #include "dvb_math.h"
>  #include "dvb_frontend.h"
> @@ -1696,12 +1697,10 @@ static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
>                 min_index = 0;
>                 if (delsys == SYS_DVBS) {
>                         cn_data = s_cn_data;
> -                       max_index = sizeof(s_cn_data) /
> -                               sizeof(s_cn_data[0]) - 1;
> +                       max_index = ARRAY_SIZE(s_cn_data) - 1;
>                 } else {
>                         cn_data = s2_cn_data;
> -                       max_index = sizeof(s2_cn_data) /
> -                               sizeof(s2_cn_data[0]) - 1;
> +                       max_index = ARRAY_SIZE(s2_cn_data) - 1;
>                 }
>                 if (value >= cn_data[min_index].value) {
>                         res = cn_data[min_index].cnr_x1000;
> diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
> index d31a2d4494d1..39357eddee32 100644
> --- a/drivers/media/pci/saa7146/hexium_gemini.c
> +++ b/drivers/media/pci/saa7146/hexium_gemini.c
> @@ -27,6 +27,7 @@
>
>  #include <media/drv-intf/saa7146_vv.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int debug;
>  module_param(debug, int, 0);
> @@ -388,7 +389,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs = HEXIUM_INPUTS,
>         .capabilities = 0,
>         .stds = &hexium_standards[0],
> -       .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
> +       .num_stds = ARRAY_SIZE(hexium_standards),
>         .std_callback = &std_callback,
>  };
>
> diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
> index 043318aa19e2..461e421080f3 100644
> --- a/drivers/media/pci/saa7146/hexium_orion.c
> +++ b/drivers/media/pci/saa7146/hexium_orion.c
> @@ -27,6 +27,7 @@
>
>  #include <media/drv-intf/saa7146_vv.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int debug;
>  module_param(debug, int, 0);
> @@ -460,7 +461,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs = HEXIUM_INPUTS,
>         .capabilities = 0,
>         .stds = &hexium_standards[0],
> -       .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
> +       .num_stds = ARRAY_SIZE(hexium_standards),
>         .std_callback = &std_callback,
>  };
>
> diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
> index 930218cc2de1..0144f305ea24 100644
> --- a/drivers/media/pci/saa7146/mxb.c
> +++ b/drivers/media/pci/saa7146/mxb.c
> @@ -30,6 +30,7 @@
>  #include <media/v4l2-common.h>
>  #include <media/i2c/saa7115.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  #include "tea6415c.h"
>  #include "tea6420.h"
> @@ -837,7 +838,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs         = MXB_INPUTS,
>         .capabilities   = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
>         .stds           = &standard[0],
> -       .num_stds       = sizeof(standard)/sizeof(struct saa7146_standard),
> +       .num_stds       = ARRAY_SIZE(standard),
>         .std_callback   = &std_callback,
>  };
>
> diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
> index 37dea0adc695..9b486bb5004d 100644
> --- a/drivers/media/usb/dvb-usb/cxusb.c
> +++ b/drivers/media/usb/dvb-usb/cxusb.c
> @@ -26,6 +26,7 @@
>  #include <media/tuner.h>
>  #include <linux/vmalloc.h>
>  #include <linux/slab.h>
> +#include <linux/kernel.h>
>
>  #include "cxusb.h"
>
> @@ -303,7 +304,7 @@ static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
>                         0x0e, 0x2, 0x47, 0x88,
>                 };
>                 msleep(20);
> -               for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
> +               for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
>                         ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
>                                              bufs+i, 4, &buf, 1);
>                         if (ret)
> diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
> index 0251a4e91d47..a6c84a4390d1 100644
> --- a/drivers/media/usb/dvb-usb/friio-fe.c
> +++ b/drivers/media/usb/dvb-usb/friio-fe.c
> @@ -13,6 +13,7 @@
>  #include <linux/init.h>
>  #include <linux/string.h>
>  #include <linux/slab.h>
> +#include <linux/kernel.h>
>
>  #include "friio.h"
>
> @@ -362,8 +363,6 @@ static u8 init_code[][2] = {
>         {0x76, 0x0C},
>  };
>
> -static const int init_code_len = sizeof(init_code) / sizeof(u8[2]);
> -
>  static int jdvbt90502_init(struct dvb_frontend *fe)
>  {
>         int i = -1;
> @@ -377,7 +376,7 @@ static int jdvbt90502_init(struct dvb_frontend *fe)
>         msg.addr = state->config.demod_address;
>         msg.flags = 0;
>         msg.len = 2;
> -       for (i = 0; i < init_code_len; i++) {
> +       for (i = 0; i < ARRAY_SIZE(init_code); i++) {
>                 msg.buf = init_code[i];
>                 ret = i2c_transfer(state->i2c, &msg, 1);
>                 if (ret != 1)
> --
> 2.14.1
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  2017-10-02  0:52   ` Jérémy Lefaure
  2017-10-02  5:35     ` Greg KH
@ 2017-10-02 16:37     ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2017-10-02 16:37 UTC (permalink / raw)
  To: Jérémy Lefaure
  Cc: Tobin C. Harding, alsa-devel, nouveau, dri-devel, dm-devel,
	brcm80211-dev-list, devel, linux-scsi, linux-rdma, amd-gfx,
	Jason Gunthorpe, linux-acpi, linux-video, intel-wired-lan,
	linux-media, intel-gfx, ecryptfs, linux-nfs, linux-raid,
	openipmi-developer, intel-gvt-dev, devel, brcm80211-dev-list.pdl,
	netdev, linux-usb, linux-wireless, linux-kernel, linux-integrity

Em Sun, 1 Oct 2017 20:52:20 -0400
Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> escreveu:

> Anyway, I can tell to each maintainer that they can apply the patches
> they're concerned about and next time I may send individual patches.

In the case of media, we'll handle it as if they were individual ones.

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  2017-10-02  5:35     ` Greg KH
@ 2017-10-02 19:22       ` J. Bruce Fields
  2017-10-03  1:33         ` Jérémy Lefaure
  0 siblings, 1 reply; 11+ messages in thread
From: J. Bruce Fields @ 2017-10-02 19:22 UTC (permalink / raw)
  To: Greg KH
  Cc: Jérémy Lefaure, Tobin C. Harding, alsa-devel, nouveau,
	dri-devel, dm-devel, brcm80211-dev-list, devel, linux-scsi,
	linux-rdma, amd-gfx, Jason Gunthorpe, linux-acpi, linux-video,
	intel-wired-lan, linux-media, intel-gfx, ecryptfs, linux-nfs,
	linux-raid, openipmi-developer, intel-gvt-dev, devel,
	brcm80211-dev-list.pdl, netdev, linux-usb, linux-wireless,
	linux-kernel, linux-integrity

On Mon, Oct 02, 2017 at 07:35:54AM +0200, Greg KH wrote:
> On Sun, Oct 01, 2017 at 08:52:20PM -0400, Jérémy Lefaure wrote:
> > On Mon, 2 Oct 2017 09:01:31 +1100
> > "Tobin C. Harding" <me@tobin.cc> wrote:
> > 
> > > > In order to reduce the size of the To: and Cc: lines, each patch of the
> > > > series is sent only to the maintainers and lists concerned by the patch.
> > > > This cover letter is sent to every list concerned by this series.  
> > > 
> > > Why don't you just send individual patches for each subsystem? I'm not a maintainer but I don't see
> > > how any one person is going to be able to apply this whole series, it is making it hard for
> > > maintainers if they have to pick patches out from among the series (if indeed any will bother
> > > doing that).
> > Yeah, maybe it would have been better to send individual patches.
> > 
> > From my point of view it's a series because the patches are related (I
> > did a git format-patch from my local branch). But for the maintainers
> > point of view, they are individual patches.
> 
> And the maintainers view is what matters here, if you wish to get your
> patches reviewed and accepted...

Mainly I'd just like to know which you're asking for.  Do you want me to
apply this, or to ACK it so someone else can?  If it's sent as a series
I tend to assume the latter.

But in this case I'm assuming it's the former, so I'll pick up the nfsd
one....

--b.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Jérémy Lefaure @ 2017-10-03  1:33 UTC (permalink / raw)
  To: J. Bruce Fields
  Cc: Greg KH, Tobin C. Harding, alsa-devel, nouveau, dri-devel,
	dm-devel, brcm80211-dev-list, devel, linux-scsi, linux-rdma,
	amd-gfx, Jason Gunthorpe, linux-acpi, linux-video,
	intel-wired-lan, linux-media, intel-gfx, ecryptfs, linux-nfs,
	linux-raid, openipmi-developer, intel-gvt-dev, devel,
	brcm80211-dev-list.pdl, netdev, linux-usb, linux-wireless,
	linux-kernel, linux-integrity, jlayton

On Mon, 2 Oct 2017 15:22:24 -0400
bfields@fieldses.org (J. Bruce Fields) wrote:

> Mainly I'd just like to know which you're asking for.  Do you want me to
> apply this, or to ACK it so someone else can?  If it's sent as a series
> I tend to assume the latter.
> 
> But in this case I'm assuming it's the former, so I'll pick up the nfsd
> one....
Could you to apply the NFSD patch ("nfsd: use ARRAY_SIZE") with the
Reviewed-by: Jeff Layton <jlayton@redhat.com>) tag please ?

This patch is an individual patch and it should not have been sent in a
series (sorry about that).

Thank you,
Jérémy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 00/18] use ARRAY_SIZE macro
  2017-10-03  1:33         ` Jérémy Lefaure
@ 2017-10-05 17:57           ` J. Bruce Fields
  0 siblings, 0 replies; 11+ messages in thread
From: J. Bruce Fields @ 2017-10-05 17:57 UTC (permalink / raw)
  To: Jérémy Lefaure
  Cc: Greg KH, Tobin C. Harding, alsa-devel, nouveau, dri-devel,
	dm-devel, brcm80211-dev-list, devel, linux-scsi, linux-rdma,
	amd-gfx, Jason Gunthorpe, linux-acpi, linux-video,
	intel-wired-lan, linux-media, intel-gfx, ecryptfs, linux-nfs,
	linux-raid, openipmi-developer, intel-gvt-dev, devel,
	brcm80211-dev-list.pdl, netdev, linux-usb, linux-wireless,
	linux-kernel, linux-integrity, jlayton

On Mon, Oct 02, 2017 at 09:33:12PM -0400, Jérémy Lefaure wrote:
> On Mon, 2 Oct 2017 15:22:24 -0400
> bfields@fieldses.org (J. Bruce Fields) wrote:
> 
> > Mainly I'd just like to know which you're asking for.  Do you want me to
> > apply this, or to ACK it so someone else can?  If it's sent as a series
> > I tend to assume the latter.
> > 
> > But in this case I'm assuming it's the former, so I'll pick up the nfsd
> > one....
> Could you to apply the NFSD patch ("nfsd: use ARRAY_SIZE") with the
> Reviewed-by: Jeff Layton <jlayton@redhat.com>) tag please ?
> 
> This patch is an individual patch and it should not have been sent in a
> series (sorry about that).

Applying for 4.15, thanks.--b.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-10-05 17:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-01 19:30 [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure
2017-10-01 19:30 ` [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure
2017-10-02 10:34   ` Michael Ira Krufky
2017-10-01 19:30 ` [PATCH 16/18] media: staging: atomisp: " Jérémy Lefaure
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

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).