From patchwork Wed Jun 5 19:00:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10977501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D14C813AD for ; Wed, 5 Jun 2019 19:01:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD80428787 for ; Wed, 5 Jun 2019 19:01:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B216E2878E; Wed, 5 Jun 2019 19:01:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57E28285FB for ; Wed, 5 Jun 2019 19:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726280AbfFETBo (ORCPT ); Wed, 5 Jun 2019 15:01:44 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51856 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725950AbfFETBo (ORCPT ); Wed, 5 Jun 2019 15:01:44 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id E414E260D04 From: Ezequiel Garcia To: Kyungmin Park , MyungJoo Ham Cc: kernel@collabora.com, linux-pm@vger.kernel.org, Enric Balletbo i Serra , Ezequiel Garcia Subject: [PATCH 1/2] PM / devfreq: Fix governor module load failure Date: Wed, 5 Jun 2019 16:00:52 -0300 Message-Id: <20190605190053.19177-1-ezequiel@collabora.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A bit unexpectedly (but still documented), request_module may return a positive value, in case of a modprobe error. This is currently causing issues in the devfreq framework. When a request_module exits with a positive value, we currently return that via ERR_PTR. However, because the value is positive, it's not a ERR_VALUE proper, and is therefore treated as a valid struct devfreq_governor pointer, leading to a kernel oops. The right way to fix this is hinted in __request_module documentation: """ [snip] The function returns zero on success or a negative errno code or positive exit code from "modprobe" on failure. Note that a successful module load does not mean the module did not then unload and exit on an error of its own. Callers must check that the service they requested is now available not blindly invoke it. """ Therefore, drop the return value check, which is not useful, and instead just re-try to find the (hopefully now loaded) governor. Fixes: 23c7b54ca1cd1 ("PM / devfreq: Fix devfreq_add_device() when drivers are built as modules.") Signed-off-by: Ezequiel Garcia Reviewed-by: Enric Balletbo i Serra --- drivers/devfreq/devfreq.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 6b6991f0e873..8868ad9472d2 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -236,7 +236,6 @@ static struct devfreq_governor *find_devfreq_governor(const char *name) static struct devfreq_governor *try_then_request_governor(const char *name) { struct devfreq_governor *governor; - int err = 0; if (IS_ERR_OR_NULL(name)) { pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); @@ -251,13 +250,10 @@ static struct devfreq_governor *try_then_request_governor(const char *name) if (!strncmp(name, DEVFREQ_GOV_SIMPLE_ONDEMAND, DEVFREQ_NAME_LEN)) - err = request_module("governor_%s", "simpleondemand"); + request_module("governor_%s", "simpleondemand"); else - err = request_module("governor_%s", name); - /* Restore previous state before return */ + request_module("governor_%s", name); mutex_lock(&devfreq_list_lock); - if (err) - return ERR_PTR(err); governor = find_devfreq_governor(name); } From patchwork Wed Jun 5 19:00:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10977503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 126B36C5 for ; Wed, 5 Jun 2019 19:02:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07A2B27F4B for ; Wed, 5 Jun 2019 19:02:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F011628737; Wed, 5 Jun 2019 19:02:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 837FB2881E for ; Wed, 5 Jun 2019 19:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726305AbfFETCr (ORCPT ); Wed, 5 Jun 2019 15:02:47 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51862 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725950AbfFETCq (ORCPT ); Wed, 5 Jun 2019 15:02:46 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id A4E54260D04 From: Ezequiel Garcia To: Kyungmin Park , MyungJoo Ham Cc: kernel@collabora.com, linux-pm@vger.kernel.org, Enric Balletbo i Serra , Ezequiel Garcia Subject: [PATCH 2/2] PM / devfreq: Sanitize prints Date: Wed, 5 Jun 2019 16:00:53 -0300 Message-Id: <20190605190053.19177-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605190053.19177-1-ezequiel@collabora.com> References: <20190605190053.19177-1-ezequiel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit is a simple cosmetic cleanup, where pr_fmt is used to avoid the "DEVFREQ" prefix in some prints. Also, messages are changed to not start with a capital. This is just a cosmetic change, meant to sanitize all prints from this file. Signed-off-by: Ezequiel Garcia --- drivers/devfreq/devfreq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 8868ad9472d2..44392fa1c570 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -10,6 +10,8 @@ * published by the Free Software Foundation. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -59,7 +61,7 @@ static struct devfreq *find_device_devfreq(struct device *dev) struct devfreq *tmp_devfreq; if (IS_ERR_OR_NULL(dev)) { - pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); + pr_err("%s: invalid parameters\n", __func__); return ERR_PTR(-EINVAL); } WARN(!mutex_is_locked(&devfreq_list_lock), @@ -208,7 +210,7 @@ static struct devfreq_governor *find_devfreq_governor(const char *name) struct devfreq_governor *tmp_governor; if (IS_ERR_OR_NULL(name)) { - pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); + pr_err("%s: invalid parameters\n", __func__); return ERR_PTR(-EINVAL); } WARN(!mutex_is_locked(&devfreq_list_lock), @@ -238,7 +240,7 @@ static struct devfreq_governor *try_then_request_governor(const char *name) struct devfreq_governor *governor; if (IS_ERR_OR_NULL(name)) { - pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); + pr_err("%s: invalid parameters\n", __func__); return ERR_PTR(-EINVAL); } WARN(!mutex_is_locked(&devfreq_list_lock), @@ -1001,7 +1003,7 @@ int devfreq_add_governor(struct devfreq_governor *governor) int err = 0; if (!governor) { - pr_err("%s: Invalid parameters.\n", __func__); + pr_err("%s: invalid parameters.\n", __func__); return -EINVAL; } @@ -1066,7 +1068,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor) int err = 0; if (!governor) { - pr_err("%s: Invalid parameters.\n", __func__); + pr_err("%s: invalid parameters.\n", __func__); return -EINVAL; }