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: 135033 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp595164lji; Fri, 4 May 2018 15:45:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoR0TGavzlu7ahZ8oeUlJ0QrBep+HJ5i7xAKIdlYeWp1jFGEA8+VHuctkYMgColy0ExEVTS X-Received: by 2002:a65:4acc:: with SMTP id c12-v6mr16514821pgu.329.1525473900673; Fri, 04 May 2018 15:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525473900; cv=none; d=google.com; s=arc-20160816; b=djmLx5X685o8SKXbjCcJz+FBV281Sz5Q+olsMa26aEAu4qCXn9ODIl8B7Q9kgG9nkR Q5ZC2rnV+t7j6fcUi1NJInf8jYhkuRnapiJqqjsiJCmrfJqfNs258N3ev4bRB814OpXL /xUGDHmOqT0QpgT1hMAyskFSHS+P17lTVPiQY3Jo1YfmTdKkuvXOBVZv+keg1n7uL0KQ gUDgCzy1+vLCB4QnLRVq2IX6a3X4ulnc/ndLis3EEVhuED1eR9TvywlPvR19QqwCQ2b2 od0sNMwYO0n9aIAvmxKsJQmnUUYuHbGDztzRF4c+ZBHv0N05atApgAzccDVvLnCf2dKy 2Oxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SKu8A7eckiZVAr4dJjKvc2EO1Etd+CIeSMA7yYs2zIc=; b=HqRh6gjGPGger9U+xh/x8ZX1mE7v+1VcGRXuYkBsh62KPczEph8o+UVgd6q3V2EBbR bzETcdrMezJahy7GHAZpEBWKWNQw9PqriKc2X9vM9/x0/98V8rnl+41J4f0yL6m0/Qd8 A/tGQJrSPr9pFMVVmruuqTU7mLy6plxyzlDRRyDgvUW7B5rmyZIVZ3zEtG/f8kO6/C7H V/mci6ge1CF8LLZceW7rdPZh1TK5AZ82waFwgxlkm/sZls9Yc7KTu/ECbHfKUKPlva+L aZKFB7igB1cg40T7NV1kBnAshA++WIAruGzn01N9LjnbjJCM59bQ/wxF8gG+RPeS6lct 4U7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bWv3775N; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si16348269pfh.92.2018.05.04.15.45.00; Fri, 04 May 2018 15:45:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b=bWv3775N; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751702AbeEDWoe (ORCPT + 10 others); Fri, 4 May 2018 18:44:34 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33673 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751748AbeEDWod (ORCPT ); Fri, 4 May 2018 18:44:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id f20so9702228pfn.0 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=GsTt90aJHGL0VWIfKe1f+gADWt3wuYpN3p5b4+wiWAeGbb7Uu98J04KVCqN1gzahXA WStr7InFz7uWmaaEVsAsEWsqZ1trvzCkxzsKm/DjQDgOaE7a3VlxUmZCtWrTleKZm6/T TrGf+f1nvdzmVPzc65zE5pjw/qnGLHqrOga8YmjNZRMWl5fFlc7VxkGdq/ihpl48Lmu/ SYWlrouDsex5QaLdcDVcuZKC7e7Cfsaoxx1AC6+tZWKyW3pSIi+IZHiPBw85/v2ZcB3K 4ZPlfNbsTS9S/6HBk45Hctfv1gGpsCguPNlHQ+rJG+LZBmUTltqkV2p2OGAVwSMPIlIV ROKg== X-Gm-Message-State: ALQs6tBL8BzIFaSCKSJIVd9NyVjtv8c92/G9qH4Rxg5AWXOl87gnunOG 1Oay9HIMGELayTqsqC2qlr9fgQ== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- Changes since v1: - None drivers/scsi/ufs/ufshcd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.17.0 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; }