From patchwork Fri Jun 19 14:33:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97623C433DF for ; Fri, 19 Jun 2020 16:32:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69C9421852 for ; Fri, 19 Jun 2020 16:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592584344; bh=73Xr/+48FOMIU+M4fpp9cEm0EyKviSfDsEVbWGtACQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CD/CPIzbsCi504RMwFAnJRAEjhYPWFUCq3o/9AbpczTeEQuumxOc8T7XssUMepRhe bAFqL6xkw3Y808y1sVqCqWFacYtkI0a49oaGQjjj7PctzW4yQHwtPxADG6Nrb/x1l9 3XOVC0w02TxXGATBr/Btzz5it4nQRpLoUgVQRA3U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389531AbgFSQcV (ORCPT ); Fri, 19 Jun 2020 12:32:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:46000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389523AbgFSOwE (ORCPT ); Fri, 19 Jun 2020 10:52:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E7AFC21852; Fri, 19 Jun 2020 14:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578324; bh=73Xr/+48FOMIU+M4fpp9cEm0EyKviSfDsEVbWGtACQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PLbp9XFv1tFA64Bgn0DK59RJi21I+BRlK8aDg1/cBLYmWjdZmFy29V/wfwa1tS2S9 dVV4yGI185/fnQ9Lu+UoWIwXGh8wOJla6HciHApWsxVpFrVx3g+9atGVcqWkRjJy+K BZKeW1RoKGLpfTLUol3Afy817v/tW4rJPZVlHKe8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tomi Valkeinen , Laurent Pinchart , Benoit Parrot , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH 4.14 170/190] media: ov5640: fix use of destroyed mutex Date: Fri, 19 Jun 2020 16:33:35 +0200 Message-Id: <20200619141642.263901370@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Tomi Valkeinen commit bfcba38d95a0aed146a958a84a2177af1459eddc upstream. v4l2_ctrl_handler_free() uses hdl->lock, which in ov5640 driver is set to sensor's own sensor->lock. In ov5640_remove(), the driver destroys the sensor->lock first, and then calls v4l2_ctrl_handler_free(), resulting in the use of the destroyed mutex. Fix this by calling moving the mutex_destroy() to the end of the cleanup sequence, as there's no need to destroy the mutex as early as possible. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Cc: stable@vger.kernel.org # v4.14+ Reviewed-by: Benoit Parrot Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/i2c/ov5640.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -2298,8 +2298,8 @@ static int ov5640_probe(struct i2c_clien free_ctrls: v4l2_ctrl_handler_free(&sensor->ctrls.handler); entity_cleanup: - mutex_destroy(&sensor->lock); media_entity_cleanup(&sensor->sd.entity); + mutex_destroy(&sensor->lock); return ret; } @@ -2309,9 +2309,9 @@ static int ov5640_remove(struct i2c_clie struct ov5640_dev *sensor = to_ov5640_dev(sd); v4l2_async_unregister_subdev(&sensor->sd); - mutex_destroy(&sensor->lock); media_entity_cleanup(&sensor->sd.entity); v4l2_ctrl_handler_free(&sensor->ctrls.handler); + mutex_destroy(&sensor->lock); return 0; }