From patchwork Fri May 4 22:44:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 10381775 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 99B526038F for ; Fri, 4 May 2018 22:45:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8432E295A8 for ; Fri, 4 May 2018 22:45:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78D60295AA; Fri, 4 May 2018 22:45:18 +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 306CD295A8 for ; Fri, 4 May 2018 22:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751864AbeEDWpR (ORCPT ); Fri, 4 May 2018 18:45:17 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:37255 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751751AbeEDWod (ORCPT ); Fri, 4 May 2018 18:44:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id e9so14499302pfi.4 for ; Fri, 04 May 2018 15:44:33 -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=SKu8A7eckiZVAr4dJjKvc2EO1Etd+CIeSMA7yYs2zIc=; b=bWv3775NQLOMdIARINXhGY/KjYnaT7u059NdZPpPx7CLOWmSH4iamwhjx7jZaBvRMa y6N0cYhMtkZ4p5F2PUFEHXw0cxhpC0fNKBG1WW/bisoiliv1DIdBlbKiJGZmE/REu6PE E+iRIZqGQiL0ohdvJU50Yjp9mkJAcL5hawT6k= 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=SKu8A7eckiZVAr4dJjKvc2EO1Etd+CIeSMA7yYs2zIc=; b=DAHH526SV+NniXVoN37wFgOqVXhrBmDTplun2zuJ1bNRUYCWVMS/ULrJRnWunViiXu KIAyxtiVPfQDoK9/l103XYLXEHV1BraUaJ/Sb5Sl8CQsK7WeBX1iluaTCRCm1nC3qddm N39isFUnJiWD2Cs2QS2rdzkCQWxk6ensufRWZm1QnaBGf55vkiKYSbYG1HeeOBqclw2w hvwfBToM2j3Udb1WNYYc5CxbzwoIm68W6UxWKKakq7Ch2LZ/Xkg3FTZxddg6JL75OFvW TI5tAo7cFXn5qB10jO251IRYZHGbnb5uY3ZIIEUvLF5FcO2wvpsf3Z1z1Z8oeVtYhQHl AQfw== X-Gm-Message-State: ALQs6tA9mJ8Mnw0n+/x5pv03/PfnYDHKaH3iAqUdIJnUw5djuHSF/cts dUSXYfYSbh81M5fnSz4thWsyNA== X-Google-Smtp-Source: AB8JxZpYHJPJKzByEgsyF7bFMBiasYwNwEMsMblgmaepIRSL4izJjyWd6c7UajvcAiBRlwIQeTjwHQ== X-Received: by 2002:a65:6250:: with SMTP id q16-v6mr8217270pgv.113.1525473872703; Fri, 04 May 2018 15:44:32 -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 b29sm34793210pfh.155.2018.05.04.15.44.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 May 2018 15:44:32 -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 v2 1/2] scsi: ufs: Extract devfreq registration Date: Fri, 4 May 2018 15:44:26 -0700 Message-Id: <20180504224427.32606-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504224427.32606-1-bjorn.andersson@linaro.org> References: <20180504224427.32606-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") Reviewed-by: Subhash Jadavani Signed-off-by: Bjorn Andersson Reviewed-by: Chanwoo Choi --- Changes since v1: - None 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; }