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: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> Reviewed-by: Michael Ira Krufky <mkrufky@linuxtv.org> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
此提交包含在:
@@ -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));
|
||||
|
新增問題並參考
封鎖使用者