Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e40d14a8 authored by Jérémy Lefaure's avatar Jérémy Lefaure Committed by Mauro Carvalho Chehab
Browse files

media: use ARRAY_SIZE



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: default avatarJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Reviewed-by: default avatarMichael Ira Krufky <mkrufky@linuxtv.org>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 37d5efb0
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -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));
+3 −4
Original line number Diff line number Diff line
@@ -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;
+2 −1
Original line number Diff line number Diff line
@@ -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,
};

+2 −1
Original line number Diff line number Diff line
@@ -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,
};

+2 −1
Original line number Diff line number Diff line
@@ -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,
};

Loading