From patchwork Fri Jun 19 14:33:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 223900 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,URIBL_BLOCKED,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 93878C433E0 for ; Fri, 19 Jun 2020 16:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6264E207FC for ; Fri, 19 Jun 2020 16:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592582462; bh=eCK/xj4hbKqq01/VVQSl0jOGuyqqRgI06S7nEiPHvTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZmNmq3YJaXoSigROytQ9ZvNRzMns6FNkeKJAhNm+1sYuQn+T0E8mf+Gau1TbIBN0O gzclOKIPQrZq5ElqKnvb0FTlF2Rn3GQD3mM2aYXWoEn9WwgcvRfaOMjYsvGmeA8Ajm Ka1adv9+MNUXJ7wj3tMhGOm1MNbLBk8vWz+EMBFo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392302AbgFSQA7 (ORCPT ); Fri, 19 Jun 2020 12:00:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:44348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392019AbgFSPNs (ORCPT ); Fri, 19 Jun 2020 11:13:48 -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 17FF72158C; Fri, 19 Jun 2020 15:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592579627; bh=eCK/xj4hbKqq01/VVQSl0jOGuyqqRgI06S7nEiPHvTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmSckPvZ1GeVTgiCTorj3/X8U17aHIrepcvq354C3k+2G7uod5yjqf6RIP3YxOVSg Hv1pa7K34Ks7WvD3AwxFBzRlsgBw5Hdm/QJB5fkM+SwXWKCE4C3lwwOGaLJ9sh8MeH 1R3QlHYIMM5fRzCXVTEP/SE7gigmP4HM1PAYusd4= 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 5.4 206/261] media: ov5640: fix use of destroyed mutex Date: Fri, 19 Jun 2020 16:33:37 +0200 Message-Id: <20200619141659.773726947@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141649.878808811@linuxfoundation.org> References: <20200619141649.878808811@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 @@ -3068,8 +3068,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; } @@ -3079,9 +3079,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; }