Skip to content

Commit f37df9a

Browse files
tombaHans Verkuil
authored andcommitted
media: v4l2-subdev: Fix alloc failure check in v4l2_subdev_call_state_try()
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>
1 parent 880c239 commit f37df9a

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
@@ -1939,19 +1939,23 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
19391939
*
19401940
* Note: only legacy non-MC drivers may need this macro.
19411941
*/
1942-
#define v4l2_subdev_call_state_try(sd, o, f, args...) \
1943-
({ \
1944-
int __result; \
1945-
static struct lock_class_key __key; \
1946-
const char *name = KBUILD_BASENAME \
1947-
":" __stringify(__LINE__) ":state->lock"; \
1948-
struct v4l2_subdev_state *state = \
1949-
__v4l2_subdev_state_alloc(sd, name, &__key); \
1950-
v4l2_subdev_lock_state(state); \
1951-
__result = v4l2_subdev_call(sd, o, f, state, ##args); \
1952-
v4l2_subdev_unlock_state(state); \
1953-
__v4l2_subdev_state_free(state); \
1954-
__result; \
1942+
#define v4l2_subdev_call_state_try(sd, o, f, args...) \
1943+
({ \
1944+
int __result; \
1945+
static struct lock_class_key __key; \
1946+
const char *name = KBUILD_BASENAME \
1947+
":" __stringify(__LINE__) ":state->lock"; \
1948+
struct v4l2_subdev_state *state = \
1949+
__v4l2_subdev_state_alloc(sd, name, &__key); \
1950+
if (IS_ERR(state)) { \
1951+
__result = PTR_ERR(state); \
1952+
} else { \
1953+
v4l2_subdev_lock_state(state); \
1954+
__result = v4l2_subdev_call(sd, o, f, state, ##args); \
1955+
v4l2_subdev_unlock_state(state); \
1956+
__v4l2_subdev_state_free(state); \
1957+
} \
1958+
__result; \
19551959
})
19561960

19571961
/**

0 commit comments

Comments
 (0)