From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 CC074C433DF for ; Fri, 19 Jun 2020 16:15:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A15032168B for ; Fri, 19 Jun 2020 16:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592583358; bh=UXODAnyXH2Tc+R2Su4d7FG46pp0SS5cd9xx6upBrECw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=R70d18++HNruTVnvkaKo2Ohbv6PEpZCfDgMxH0bvsixBINFrdEDViUuLQFanzh3RB 2dgSAWGqWCVe28OiLzXf2MgByLimgUUzW4XQ40bBLgOG8nQ74SvUsMOXoSqZzWeSdJ S9TxJeAdEW2VCsZVutBk55FlMW/8tV+wOZncYw5Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389254AbgFSQPu (ORCPT ); Fri, 19 Jun 2020 12:15:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:60196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391002AbgFSPD1 (ORCPT ); Fri, 19 Jun 2020 11:03:27 -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 85E4021841; Fri, 19 Jun 2020 15:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592579007; bh=UXODAnyXH2Tc+R2Su4d7FG46pp0SS5cd9xx6upBrECw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hl3z1WCdzEtyNxVWYYApOJ7ipS6W8bZwaJU302jzGyCxKKHzrYJkCnwOYRfrNIZjh uBQ9tSm1sc8HuAZt9r4/KF1orvRng6TfSsH7I923dchuCwIj9ZOscSCKieV8awAEEz Oc+QeD5zK3ysIgNfzeMBAQncprabguCL7aedeH80= 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.19 240/267] media: ov5640: fix use of destroyed mutex Date: Fri, 19 Jun 2020 16:33:45 +0200 Message-Id: <20200619141700.208218465@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 @@ -2829,8 +2829,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; } @@ -2840,9 +2840,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; }