]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: fix warning on v4l2_subdev_call() result interpreted as bool
authorArnd Bergmann <arnd@arndb.de>
Wed, 19 Jul 2017 19:23:27 +0000 (15:23 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 26 Jul 2017 17:43:17 +0000 (13:43 -0400)
v4l2_subdev_call is a macro returning whatever the callback return
type is, usually 'int'. With gcc-7 and ccache, this can lead to
many wanings like:

media/platform/pxa_camera.c: In function 'pxa_mbus_build_fmts_xlate':
media/platform/pxa_camera.c:766:27: error: ?: using integer constants in boolean context [-Werror=int-in-bool-context]
  while (!v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, &code)) {
media/atomisp/pci/atomisp2/atomisp_cmd.c: In function 'atomisp_s_ae_window':
media/atomisp/pci/atomisp2/atomisp_cmd.c:6414:52: error: ?: using integer constants in boolean context [-Werror=int-in-bool-context]
  if (v4l2_subdev_call(isp->inputs[asd->input_curr].camera,

The problem here is that after preprocessing, we the compiler
sees a variation of

if (a ? 0 : 2)

that it thinks is suspicious.

This replaces the ?: operator with an different expression that
does the same thing in a more easily readable way that cannot
tigger the warning

Link: https://lkml.org/lkml/2017/7/14/156
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
include/media/v4l2-subdev.h

index 0f92ebd2d7101acf66ff8cc5e83f8524e573332a..e83872078376a9874f68ae1362478e1a881b83ae 100644 (file)
@@ -982,8 +982,16 @@ void v4l2_subdev_init(struct v4l2_subdev *sd,
  * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  */
 #define v4l2_subdev_call(sd, o, f, args...)                            \
-       (!(sd) ? -ENODEV : (((sd)->ops->o && (sd)->ops->o->f) ? \
-               (sd)->ops->o->f((sd), ##args) : -ENOIOCTLCMD))
+       ({                                                              \
+               int __result;                                           \
+               if (!(sd))                                              \
+                       __result = -ENODEV;                             \
+               else if (!((sd)->ops->o && (sd)->ops->o->f))            \
+                       __result = -ENOIOCTLCMD;                        \
+               else                                                    \
+                       __result = (sd)->ops->o->f((sd), ##args);       \
+               __result;                                               \
+       })
 
 #define v4l2_subdev_has_op(sd, o, f) \
        ((sd)->ops->o && (sd)->ops->o->f)