Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3439317ybl; Tue, 21 Jan 2020 00:26:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwg7DrEyNOf5F+Iy8CuW0Ng4Wur+r5fYwvlXaG2NVQYmBZ3mx+UQ5wX5Lhx5WBllLS6eXOP X-Received: by 2002:a05:6808:6d6:: with SMTP id m22mr2071262oih.138.1579595168039; Tue, 21 Jan 2020 00:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579595168; cv=none; d=google.com; s=arc-20160816; b=HrBJ65UCectnQhFxy5QBZKz6kMtuZJYbRL/hMNIykGz2N6ZJ/JNiClJdCFeXhl4BZB z/WcRF40Ur0A3JO5yooV2+oPfoWoRYGeK4bmXLXQISXTHvHJlksJuOq1lClLfKNwSFK6 h7SuBRMcu2fjRNKF9q6OpLNsikefpZct/6f9eNxgOqho0nxdmSAxL8U9Z7Chd3gb1x29 Pf0/ysV8sfrxFgyqGE/vcBk60fPpqVW0yPOXkrZ3QXrU8mNrBHPDn3mJIMDTe8+va9M/ +ou8Uq3wI7C4bvb70srow0jIcMNGjxH7sAi17q8mb2uojbGsI18BKtdEnRmB0yRcMTe8 0dsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=h3m0tET0nyzw5YESJu5Z6SDP7rIP3J5dJWD62OmBGcs=; b=XYlufGTfxJMt5X6xQv3q2DJHUCV1fO/iUF+4mKiK6Da35RhL37Lgj2o+RWfE4QPry3 oSnURkdann1N2hM1TrFP08hxDyamcJbsHHO4jRFnlitTpmOlGHtiRyk8+THpsdNPl2R4 SKpyX1IROo+p6haDzoCcNA+0uNk/8gom+9GaGccZTBZMpx/qRnv/jJWKaah/OgRw26Ee cVm47IpnqeOOZxd+w9t+xq+H9Aug0lUn2B4ClvrNpx2zAoPP88//1+7o+ts4oplTVWhl zmRfYHoKKB4UZIhD1JllOkv2HMM2Su/Wd5R7JPib9X/h76P8lcr7wA+ZxSRNxVWGbhA8 NyBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17si21557386otp.131.2020.01.21.00.25.56; Tue, 21 Jan 2020 00:26:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727847AbgAUIX6 (ORCPT + 99 others); Tue, 21 Jan 2020 03:23:58 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:40125 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbgAUIX6 (ORCPT ); Tue, 21 Jan 2020 03:23:58 -0500 Received: from litschi.hi.pengutronix.de ([2001:67c:670:100:feaa:14ff:fe6a:8db5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1itopE-0007Mk-S7; Tue, 21 Jan 2020 09:23:52 +0100 Date: Tue, 21 Jan 2020 09:23:50 +0100 From: Michael Tretter To: Chuhong Yuan Cc: Pengutronix Kernel Team , Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] media: allegro: add missed checks in allegro_open() Message-ID: <20200121092350.466f62a8@litschi.hi.pengutronix.de> In-Reply-To: <20200113055951.8718-1-hslester96@gmail.com> References: <20200113055951.8718-1-hslester96@gmail.com> Organization: Pengutronix X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:100:feaa:14ff:fe6a:8db5 X-SA-Exim-Mail-From: m.tretter@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 13 Jan 2020 13:59:51 +0800, Chuhong Yuan wrote: > allegro_open() misses checks for v4l2_m2m_ctx_init() and results of > v4l2_ctrl_new* calls. > Add checks and error handlers to fix the problems. > > Signed-off-by: Chuhong Yuan > --- > Changes in v3: > - Make code cleaner. > - Add a check for handler->error. > > .../staging/media/allegro-dvt/allegro-core.c | 24 +++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/drivers/staging/media/allegro-dvt/allegro-core.c b/drivers/staging/media/allegro-dvt/allegro-core.c > index 6f0cd0784786..e86001e42963 100644 > --- a/drivers/staging/media/allegro-dvt/allegro-core.c > +++ b/drivers/staging/media/allegro-dvt/allegro-core.c > @@ -2270,15 +2270,12 @@ static int allegro_open(struct file *file) > struct allegro_channel *channel = NULL; > struct v4l2_ctrl_handler *handler; > u64 mask; > + int ret; > > channel = kzalloc(sizeof(*channel), GFP_KERNEL); > if (!channel) > return -ENOMEM; > > - v4l2_fh_init(&channel->fh, vdev); > - file->private_data = &channel->fh; > - v4l2_fh_add(&channel->fh); > - > init_completion(&channel->completion); > > channel->dev = dev; > @@ -2328,6 +2325,11 @@ static int allegro_open(struct file *file) > V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, > 1, 32, > 1, 1); > + if (handler->error != 0) { > + ret = handler->error; > + goto error; > + } > + > channel->fh.ctrl_handler = handler; > > channel->mcu_channel_id = -1; > @@ -2341,7 +2343,21 @@ static int allegro_open(struct file *file) > channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel, > allegro_queue_init); > > + if (IS_ERR(channel->fh.m2m_ctx)) { > + ret = PTR_ERR(channel->fh.m2m_ctx); > + goto error; > + } > + > + v4l2_fh_init(&channel->fh, vdev); This call sets channel->fh.ctrl_handler to vdev->ctrl_handler, which has previously been overriden by the driver to handler. Therefore, this patch breaks all controls. I think we should initialize channel->fh before setting any fields of this struct. Michael > + file->private_data = &channel->fh; > + v4l2_fh_add(&channel->fh); > + > return 0; > + > +error: > + v4l2_ctrl_handler_free(handler); > + kfree(channel); > + return ret; > } > > static int allegro_release(struct file *file)