Commit 12891698 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

media: xilinx: simplify get fourcc logic

Right now, there are two calls for xvip_get_format_by_fourcc().
If the first one fails, it is called again in order to pick
the first available format: V4L2_PIX_FMT_YUYV.

This ends by producing a smatch warnings:
	drivers/media/platform/xilinx/xilinx-dma.c:555 __xvip_dma_try_format() error: 'info' dereferencing possible ERR_PTR()
	drivers/media/platform/xilinx/xilinx-dma.c: drivers/media/platform/xilinx/xilinx-dma.c:664 xvip_dma_init() error: 'dma->fmtinfo' dereferencing possible ERR_PTR()

as it is hard for an static analyzer to ensure that calling
xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT) won't return an
error.

So, better to optimize the logic, ensuring that the function
will never return an error.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 60f0618d
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "xilinx-vip.h" #include "xilinx-vip.h"
#include "xilinx-vipp.h" #include "xilinx-vipp.h"
#define XVIP_DMA_DEF_FORMAT V4L2_PIX_FMT_YUYV
#define XVIP_DMA_DEF_WIDTH 1920 #define XVIP_DMA_DEF_WIDTH 1920
#define XVIP_DMA_DEF_HEIGHT 1080 #define XVIP_DMA_DEF_HEIGHT 1080
...@@ -549,8 +548,6 @@ __xvip_dma_try_format(struct xvip_dma *dma, struct v4l2_pix_format *pix, ...@@ -549,8 +548,6 @@ __xvip_dma_try_format(struct xvip_dma *dma, struct v4l2_pix_format *pix,
* requested format isn't supported. * requested format isn't supported.
*/ */
info = xvip_get_format_by_fourcc(pix->pixelformat); info = xvip_get_format_by_fourcc(pix->pixelformat);
if (IS_ERR(info))
info = xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT);
pix->pixelformat = info->fourcc; pix->pixelformat = info->fourcc;
pix->field = V4L2_FIELD_NONE; pix->field = V4L2_FIELD_NONE;
...@@ -660,7 +657,7 @@ int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma, ...@@ -660,7 +657,7 @@ int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma,
INIT_LIST_HEAD(&dma->queued_bufs); INIT_LIST_HEAD(&dma->queued_bufs);
spin_lock_init(&dma->queued_lock); spin_lock_init(&dma->queued_lock);
dma->fmtinfo = xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT); dma->fmtinfo = xvip_get_format_by_fourcc(V4L2_PIX_FMT_YUYV);
dma->format.pixelformat = dma->fmtinfo->fourcc; dma->format.pixelformat = dma->fmtinfo->fourcc;
dma->format.colorspace = V4L2_COLORSPACE_SRGB; dma->format.colorspace = V4L2_COLORSPACE_SRGB;
dma->format.field = V4L2_FIELD_NONE; dma->format.field = V4L2_FIELD_NONE;
......
...@@ -70,8 +70,8 @@ EXPORT_SYMBOL_GPL(xvip_get_format_by_code); ...@@ -70,8 +70,8 @@ EXPORT_SYMBOL_GPL(xvip_get_format_by_code);
* @fourcc: the format 4CC * @fourcc: the format 4CC
* *
* Return: a pointer to the format information structure corresponding to the * Return: a pointer to the format information structure corresponding to the
* given V4L2 format @fourcc, or ERR_PTR if no corresponding format can be * given V4L2 format @fourcc. If not found, return a pointer to the first
* found. * available format (V4L2_PIX_FMT_YUYV).
*/ */
const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc) const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc)
{ {
...@@ -84,7 +84,7 @@ const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc) ...@@ -84,7 +84,7 @@ const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc)
return format; return format;
} }
return ERR_PTR(-EINVAL); return &xvip_video_formats[0];
} }
EXPORT_SYMBOL_GPL(xvip_get_format_by_fourcc); EXPORT_SYMBOL_GPL(xvip_get_format_by_fourcc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment