Skip to content

Commit 94e6336

Browse files
tombagregkh
authored andcommitted
media: v4l2-subdev: Fix alloc failure check in v4l2_subdev_call_state_try()
commit f37df9a upstream. v4l2_subdev_call_state_try() macro allocates a subdev state with __v4l2_subdev_state_alloc(), but does not check the returned value. If __v4l2_subdev_state_alloc fails, it returns an ERR_PTR, and that would cause v4l2_subdev_call_state_try() to crash. Add proper error handling to v4l2_subdev_call_state_try(). Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Fixes: 982c048 ("media: subdev: Add v4l2_subdev_call_state_try() macro") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/all/aJTNtpDUbTz7eyJc%40stanley.mountain/ Cc: stable@vger.kernel.org Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0cd821d commit 94e6336

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

include/media/v4l2-subdev.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,19 +1952,23 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
19521952
*
19531953
* Note: only legacy non-MC drivers may need this macro.
19541954
*/
1955-
#define v4l2_subdev_call_state_try(sd, o, f, args...) \
1956-
({ \
1957-
int __result; \
1958-
static struct lock_class_key __key; \
1959-
const char *name = KBUILD_BASENAME \
1960-
":" __stringify(__LINE__) ":state->lock"; \
1961-
struct v4l2_subdev_state *state = \
1962-
__v4l2_subdev_state_alloc(sd, name, &__key); \
1963-
v4l2_subdev_lock_state(state); \
1964-
__result = v4l2_subdev_call(sd, o, f, state, ##args); \
1965-
v4l2_subdev_unlock_state(state); \
1966-
__v4l2_subdev_state_free(state); \
1967-
__result; \
1955+
#define v4l2_subdev_call_state_try(sd, o, f, args...) \
1956+
({ \
1957+
int __result; \
1958+
static struct lock_class_key __key; \
1959+
const char *name = KBUILD_BASENAME \
1960+
":" __stringify(__LINE__) ":state->lock"; \
1961+
struct v4l2_subdev_state *state = \
1962+
__v4l2_subdev_state_alloc(sd, name, &__key); \
1963+
if (IS_ERR(state)) { \
1964+
__result = PTR_ERR(state); \
1965+
} else { \
1966+
v4l2_subdev_lock_state(state); \
1967+
__result = v4l2_subdev_call(sd, o, f, state, ##args); \
1968+
v4l2_subdev_unlock_state(state); \
1969+
__v4l2_subdev_state_free(state); \
1970+
} \
1971+
__result; \
19681972
})
19691973

19701974
/**

0 commit comments

Comments
 (0)