From: Mauro Carvalho Chehab Date: Fri, 7 Dec 2018 11:13:48 +0000 (-0500) Subject: media: cetrus: return an error if alloc fails X-Git-Tag: v5.15~7385^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ed5d5fb8b432badc967decf97e4294cbb216eef;p=platform%2Fkernel%2Flinux-starfive.git media: cetrus: return an error if alloc fails As warned by smatch: drivers/staging/media/sunxi/cedrus/cedrus.c: drivers/staging/media/sunxi/cedrus/cedrus.c:93 cedrus_init_ctrls() error: potential null dereference 'ctx->ctrls'. (kzalloc returns null) While here, remove the memset(), as kzalloc() already zeroes the struct. Signed-off-by: Mauro Carvalho Chehab Acked-by: Paul Kocialkowski Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c index 67b1823..4711df7 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c @@ -72,7 +72,8 @@ static int cedrus_init_ctrls(struct cedrus_dev *dev, struct cedrus_ctx *ctx) ctrl_size = sizeof(ctrl) * CEDRUS_CONTROLS_COUNT + 1; ctx->ctrls = kzalloc(ctrl_size, GFP_KERNEL); - memset(ctx->ctrls, 0, ctrl_size); + if (!ctx->ctrls) + return -ENOMEM; for (i = 0; i < CEDRUS_CONTROLS_COUNT; i++) { struct v4l2_ctrl_config cfg = { 0 };