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: 10358409 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 F05436038F for ; Tue, 24 Apr 2018 00:21:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFF7828C9B for ; Tue, 24 Apr 2018 00:21:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D46D728CA3; Tue, 24 Apr 2018 00:21:15 +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 8822128C9B for ; Tue, 24 Apr 2018 00:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932676AbeDXAVE (ORCPT ); Mon, 23 Apr 2018 20:21:04 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:42567 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932652AbeDXAUW (ORCPT ); Mon, 23 Apr 2018 20:20:22 -0400 Received: by mail-pf0-f193.google.com with SMTP id o16so10680126pfk.9 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=UjzudYorCCNbtxFMHIs9RztK3DTzX3mrKC28Rab3IOxrC3Wht8rgyVLSbfV7QxafvQ Fvun63R2oAf6YQXXiPLrp6pYLs+pd5wJ/O8rq9V6IsTRRw6gQ8E2VGACtjPhoSu9aXno +E0y6SiJXum22nwOBJGesjZSg/3J/astxzV6JidORk2+l590lMD5cAMQM1Ox1mj4Py4i NJe1KSnYtFlEmCCnbPK3h0imEuLJ1Tn+PqyPNndusXFV8lqs9Er+oyQXhfLukAkVKvr9 Ax/29GM41MVvReHLDLW72G8YfcN0V+8eWRNGa3MyFngUea1bWZr45cRHSJqSx+g122Jy nyNg== X-Gm-Message-State: ALQs6tAS+Wn6BWli97PqRgh5wYCsbubHNsFG09mMVfplA3aIAEhweIkC BUnRY0g1Bko419CeTOB7NMq6gw== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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; }