Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp46210pja; Fri, 22 Nov 2019 03:15:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwaFqCTaXt/33xTvLjDyM+U0rj+1C8+6FaapLlim2kfoC86XvEsbJk5hYAYXhIjErv6WhRV X-Received: by 2002:a17:906:2444:: with SMTP id a4mr21598845ejb.134.1574421334067; Fri, 22 Nov 2019 03:15:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421334; cv=none; d=google.com; s=arc-20160816; b=rGeii5FXxJtfdJnpFVPwAKHZbxKeDbA2Ly0USkFP8eTpdaD2JbozUtdHRaZpochrBc uHVmPrrU1D4rFl32rhiDBft2SV0pjKGj+gUFq4N22/zhyJ/T6CntroHxjFpKxmCw3G9R 41Y279k/qvVWgZ4aclNvv66kHDThouRyfWb5CLDUFypXuazUUXEQ2wx1cVq58gB7kUjm 6hVx6Tr0XNBbxm0IHKhZw4mjS5yXYG4Z2s4TJOpO1kmxIlhCOD7eUWnyMk/J1l4WifEt z2aKEMQArPbgsbN+7HK4Uc+USNfvnv464tbnkLEFdMjGbNIVY7ILtkGUYStT9M+R3n5M 5XWw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8eMyPc7y3WuT0DL9XIIonzIW3zai1T8BwVadOuyYSrs=; b=iZxvwBE2jgmQMysiT+pKholYsbkKxFR9lEIHGhORfJQCui4VWFpy0zYgVm5vLvFs9o Zq0Lyf1DFqYBsmommTDBubSBVLGKMF8//E0ksIyVDxycPjxhbPCVkkb9/xI9Yb5E00ne SPSiFT/YF3klhROsSWnBAAoLa8WdijS+qat3FHdP+65cZowTCvg6cyTflq7VWRZAOALD +tx1ByW/xNw+bO19xJxQEkf94JZ/pb3QzX0zDao+m9+4tRxer0tpJ3CjWt40mQRzTs4m /rx9EpuHCwEBR+QSux7ZASyEGi+j293XHl2P+eTyvnEBFSfr8sP5LpxgH+zZG5qj4Ele ExQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rIk0FCeN; 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 a7si4370174edt.181.2019.11.22.03.15.10; Fri, 22 Nov 2019 03:15:34 -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; dkim=pass header.i=@kernel.org header.s=default header.b=rIk0FCeN; 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 S1730464AbfKVLMp (ORCPT + 99 others); Fri, 22 Nov 2019 06:12:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:46386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727468AbfKVK52 (ORCPT ); Fri, 22 Nov 2019 05:57:28 -0500 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 80C062071C; Fri, 22 Nov 2019 10:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574420248; bh=S3t5Cafj8u2c9Tf3AxCsWdFvcbncy3FrspDvoheR4uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rIk0FCeNCQCQzxL1CXNmcDFIzs6N7sfmh4soThdpyBURNoNfUlwldxM8AIbWjEuq7 FoCYKy86ZQOeTZud8qkoh1lcPjNZtz1N3EbhrUgeQ8u4QTqW1zqLdmui4maKO5b6zk 6CTwLrJBKRHwTLqJvdDamxA9+Uka40uRLw/ug2FE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Donnefort , John Einar Reitan , Chanwoo Choi , MyungJoo Ham , Sasha Levin Subject: [PATCH 4.19 043/220] PM / devfreq: stopping the governor before device_unregister() Date: Fri, 22 Nov 2019 11:26:48 +0100 Message-Id: <20191122100915.371382417@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100912.732983531@linuxfoundation.org> References: <20191122100912.732983531@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Donnefort [ Upstream commit 2f061fd0c2d852e32e03a903fccd810663c5c31e ] device_release() is freeing the resources before calling the device specific release callback which is, in the case of devfreq, stopping the governor. It is a problem as some governors are using the device resources. e.g. simpleondemand which is using the devfreq deferrable monitoring work. If it is not stopped before the resources are freed, it might lead to a use after free. Signed-off-by: Vincent Donnefort Reviewed-by: John Einar Reitan [cw00.choi: Fix merge conflict] Reviewed-by: Chanwoo Choi Signed-off-by: MyungJoo Ham Signed-off-by: Sasha Levin --- drivers/devfreq/devfreq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 8e21bedc74c38..bcd2279106760 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -578,10 +578,6 @@ static void devfreq_dev_release(struct device *dev) list_del(&devfreq->node); mutex_unlock(&devfreq_list_lock); - if (devfreq->governor) - devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_STOP, NULL); - if (devfreq->profile->exit) devfreq->profile->exit(devfreq->dev.parent); @@ -717,7 +713,7 @@ struct devfreq *devfreq_add_device(struct device *dev, err_init: mutex_unlock(&devfreq_list_lock); - device_unregister(&devfreq->dev); + devfreq_remove_device(devfreq); devfreq = NULL; err_dev: if (devfreq) @@ -738,6 +734,9 @@ int devfreq_remove_device(struct devfreq *devfreq) if (!devfreq) return -EINVAL; + if (devfreq->governor) + devfreq->governor->event_handler(devfreq, + DEVFREQ_GOV_STOP, NULL); device_unregister(&devfreq->dev); return 0; -- 2.20.1