Received: by 10.192.165.148 with SMTP id m20csp585069imm; Fri, 4 May 2018 15:46:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8R6j382Z7JX+6Ggfydyw8vn72ficAJVKT/aXK8eDEHNnRt230BHw4nIEdNK2dWa/zPK2F X-Received: by 10.98.98.194 with SMTP id w185mr22545782pfb.78.1525474015631; Fri, 04 May 2018 15:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525474015; cv=none; d=google.com; s=arc-20160816; b=gc7pYP12oSbeuMXfp6rCo+s76x7h39jNjuK8ZP45976IZhS9NBYD0qH6ASRY1eOcri a9tzKnmMUWwUDXI0xaOo4OsCR7B84KkIPw++745GUACNx/PoWnYV/dsE9N2tgdG1pTnM 6P369j5qvp8uWvHMWXodvc0mcDhGdRBJTegEfWEfcdEcLvFOOYTUAluCDFVriBHjFV5p pM25oLtfi/k9O3pq9PFWR7h6sjCinUalusEtVndbaG1/KEXluAsCAf3BP2+wbPmThdSS +rK/d35alvGCi2imTDhknA7U63bH38/gsNbdf6HdmDZoGbDe4U9L1RoTGaJjFmRFC0qA D0fA== 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=owD0Ain7SQ23GaUmh+7Eenj4lA0gS4KYhp68BHFN5h2yapo4RMXJhxNYRGbjzygu3o mbvlyYT4a7CzKJNVcDwFzgVrMnP5kPlf2DLp7ijPjSTjsVKlUiC4ZR3/yJSSsWbV+RpE Ws0fHtYOWXziQefHLq27gQWbhs4sbPA1NLidIJZeAyorHSmEwrgq58W1Aew6A8RKVLJL J2Dv+er3yv/TN9AcC4mALFRISjlPae3naF+ItMyESzHC1LFt+yn/Q9/pPj4uOw1A/z3v AFwJZRdXN08Yc7W/5mjfvwl+rLSH/gYXE2wlmtUUb3J/DLvUSprdQYtZHDDlawXwDNlv eD2A== 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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 h67si17398511pfk.15.2018.05.04.15.46.41; Fri, 04 May 2018 15:46:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751852AbeEDWpE (ORCPT + 99 others); Fri, 4 May 2018 18:45:04 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44332 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751759AbeEDWod (ORCPT ); Fri, 4 May 2018 18:44:33 -0400 Received: by mail-pf0-f196.google.com with SMTP id q22so18491755pff.11 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=GVHpBC6gqHDsgegpQbme/FumYSQ5cuMt9j+TI7dYnMLlL3VosRgPRKiQQqDg2NQPWG e7oTa3/hQkok/AEHop3fTjrnYA0XKJi2/GakN6KAf+BLBL6mhAAfMcX7eLJSJO7gmhUG V+SKKmIY9ubad+yFj8yLEdTltSSlFCikyDkVdL6SJTOv9GOiYxBpl81sAP0FyshKiWX5 ixIbXzMkbJGaItFpwjYQpHvc0mcNv+K4+x7yq6AHxGPFmX0F8oYQSYaP7kRg+ux71J2Z l4T31Wmrg2cZvW1QHbJqJe5i/RJ4UxziCBEgM58B+99Mn9LNq/dpPpkzNnQW1ZVvB8Uu /8GQ== X-Gm-Message-State: ALQs6tDemiQm30NKbBd63B4idbM0JrZ3ZT2B47jM2zxPTdFxDlgaM3jO AFqMnBg/K0b8RNu70HIU0CEFqA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; } -- 2.17.0