From patchwork Tue Apr 24 00:20:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 10358413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CEC560225 for ; Tue, 24 Apr 2018 00:21:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C83D28C9B for ; Tue, 24 Apr 2018 00:21:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6128A28CA3; Tue, 24 Apr 2018 00:21:17 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 DD5F628C9B for ; Tue, 24 Apr 2018 00:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932697AbeDXAVD (ORCPT ); Mon, 23 Apr 2018 20:21:03 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36021 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932676AbeDXAUW (ORCPT ); Mon, 23 Apr 2018 20:20:22 -0400 Received: by mail-pf0-f196.google.com with SMTP id g14so10690735pfh.3 for ; Mon, 23 Apr 2018 17:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=J2s69UbsahGMzxJIdQWi4bfO6OZ8ercD2J74i+LalmAZKU3tOwlIPdZBrzYQzoaJcN kkviA5WBDjS8yL333Gj/4GLx9MTFd0GByph3zAW6HYQNVDZJAICyQHGqEWIculhRMw3E xdBnUggCuw3Q4OkG0p50nxH9E26jGZ0c/zp2U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=AMOHfDBCoEP9IDKqEah2Bf5FLRkMM/VlgE64SLRWUduYgarNQW/RZp8eDalv+W5siw gx0WMuB7KUDByG5STNcnULFrstcp1uHKj3bzzGSizW5OOePIBQpvkYdiD34h7xAY411i JY7JEm4aWD8cPm0Z7/Gsg0tYlEmV16Zz0FYjWt7dIi1n8zBShRhEEH2TAaYFmpicQB2C jbOk6zrReFtDXgtdfbdBBctrYnf/cavLNmjg0m1v2EBrNW9BXdx2NmJY7k2l8c4oGxIz OvBBpt6cB/AdbC/aiaD1cyxFp7r122iitwB0be0iJ0ml8Mm65mzsgaiTKUjsDL7lbFyh B5ig== X-Gm-Message-State: ALQs6tBH18pbQcb/Q3GrL4eX92kGLlejgenLODgcdiFObBhxdQ4O4hi/ f/StXH2dtechz07kTC0swQLwtw== X-Google-Smtp-Source: AIpwx4/jc+WlNJmLZSZ69ccpSljW39wLA8ssKEemfBGPDgAANhccByhzrZ6Ct+ZI+mX9Ariv1a42PA== X-Received: by 10.98.14.7 with SMTP id w7mr21747324pfi.50.1524529222072; Mon, 23 Apr 2018 17:20:22 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id p6sm26669845pfk.104.2018.04.23.17.20.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 17:20:21 -0700 (PDT) From: Bjorn Andersson To: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" Cc: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vivek Gautam Subject: [PATCH 2/3] scsi: ufs: Extract devfreq registration Date: Mon, 23 Apr 2018 17:20:15 -0700 Message-Id: <20180424002016.9205-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180424002016.9205-1-bjorn.andersson@linaro.org> References: <20180424002016.9205-1-bjorn.andersson@linaro.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Failing to register with devfreq leaves hba->devfreq assigned, which causes the error path to dereference the ERR_PTR(). Rather than bolting on more conditionals, move the call of devm_devfreq_add_device() into it's own function and only update hba->devfreq once it's successfully registered. The subsequent patch builds upon this to make UFS actually work again, as it's been broken since f1d981eaecf8 ("PM / devfreq: Use the available min/max frequency") Signed-off-by: Bjorn Andersson Reviewed-by: Subhash Jadavani --- drivers/scsi/ufs/ufshcd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8f22a980b1a7..2253f24309ec 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1255,6 +1255,26 @@ static struct devfreq_dev_profile ufs_devfreq_profile = { .get_dev_status = ufshcd_devfreq_get_dev_status, }; +static int ufshcd_devfreq_init(struct ufs_hba *hba) +{ + struct devfreq *devfreq; + int ret; + + devfreq = devm_devfreq_add_device(hba->dev, + &ufs_devfreq_profile, + "simple_ondemand", + NULL); + if (IS_ERR(devfreq)) { + ret = PTR_ERR(devfreq); + dev_err(hba->dev, "Unable to register with devfreq %d\n", ret); + return ret; + } + + hba->devfreq = devfreq; + + return 0; +} + static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba) { unsigned long flags; @@ -6399,16 +6419,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) sizeof(struct ufs_pa_layer_attr)); hba->clk_scaling.saved_pwr_info.is_valid = true; if (!hba->devfreq) { - hba->devfreq = devm_devfreq_add_device(hba->dev, - &ufs_devfreq_profile, - "simple_ondemand", - NULL); - if (IS_ERR(hba->devfreq)) { - ret = PTR_ERR(hba->devfreq); - dev_err(hba->dev, "Unable to register with devfreq %d\n", - ret); + ret = ufshcd_devfreq_init(hba); + if (ret) goto out; - } } hba->clk_scaling.is_allowed = true; }