From patchwork Fri May 18 06:26:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 136245 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp840996lji; Thu, 17 May 2018 23:27:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZodYeTO4Rr+E0vbUKc4vk29V0kCQ+O5smpIhgzx1AWy/IvF5sriAUCqEMwwaNFA+kcekU7/ X-Received: by 2002:a63:be4b:: with SMTP id g11-v6mr6519296pgo.41.1526624858258; Thu, 17 May 2018 23:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526624858; cv=none; d=google.com; s=arc-20160816; b=XdOTsCRBzKP9LVzvzGX43/Cqso1dKcA9ixvrWBZXndw2NlQTF3rAwylbFVEQqH9mTV L+RxWyjytQIeadVjnJDiVLxZJGZ/jaQIeKAqv8koU0d3pHaZfwo3OrlQN5rV6Y2spP/v wCOfrpltBr9lcgdCSSIfwKmjWJD9Yom4/KwVz50DLNUon8jQsOCYnNw/2fBoEqC7AYxo TMvVrb4zDwQm2SwWCayOzGCreauGnCltdQBVPHkFKzqtKCcc+r/jZB7oKIP9LuFJfugD 8o9dinrZU1ThOuIgv26TioubeA/d+EtrQnqFK//tiOEgPFI8WrngOw+I4bmlnAUslWdi DqpA== 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=nTiw+f5+gsdqj+kWCtq8rekmxjC90c6YvOzWJLB+vwo=; b=Cx9T7bdGguc1Xkfbw7i2L3ms2EoZfhsuTgvcnxjzGQszkGdbzLboEevos475uo+ENA 0SmDzyUsHAiZEXLRjblltkdinvhidh/EiGKdwhCDJ5Btw6uXmIiPo9MWLDoFp17wBte+ Dgv7Ph4oTANfUNJNl+08cx6dDy85cB6jjm2RaJ2Q6TFWlLUTYJ+QAA3ltoQkqL0LBOIP fexKQmfB91rkxMlYwQQb3mHF0hZGFSetmsDOmXd08jfMjjvFHlMQFrNL9z59L0Vq+fPF 4v524XQiiyl5J/HllVeBghb13rwCCPXj7v4DC5djCxR21ONYsqIWsj7OZu9fC2Qamixr N2Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGajjgPa; 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 b93-v6si6844388plb.536.2018.05.17.23.27.37; Thu, 17 May 2018 23:27:38 -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=HGajjgPa; 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 S1752273AbeERG1e (ORCPT + 29 others); Fri, 18 May 2018 02:27:34 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42322 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752022AbeERG0n (ORCPT ); Fri, 18 May 2018 02:26:43 -0400 Received: by mail-pl0-f65.google.com with SMTP id u6-v6so3981023pls.9 for ; Thu, 17 May 2018 23:26:43 -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=nTiw+f5+gsdqj+kWCtq8rekmxjC90c6YvOzWJLB+vwo=; b=HGajjgPaIGenYozRpUboyZEqoWdHvNV4o8TNrsBih4gPiquNdF6Qry7NgJM8KPqysE IHMkQmzgSagEBylXVQTYZb1kt3TP6Bj5ho3mEJlECIbYYFBAb6B7V0mhMvYCWZUdYXfv xzyeUKhNY3pWvJqzMwv01MRvhs/QhIZIVKTaU= 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=nTiw+f5+gsdqj+kWCtq8rekmxjC90c6YvOzWJLB+vwo=; b=Uy4FPLFhuVV+p77YO+MeCtkvxL2rI+c7lA4W+pVjldB+lEdofWV4846e6sfeo2SYa2 vnZngltk/6jmFuHe5NdLE/Exu7Bwk522cV1vVpJ5IkQLBCpmjgNrVah2JnsS/sVvzoOt 3DzG5o/CnX4VCPR28+WOq9YhW/mA+xdiubJuYF5FNKd4ekMm9VIilYu8PwoicQY2AOFw VcaSSafsRG6dySZ1qfyGNIjm2VD5GwI/qfvdBnu/60zCrGJfUXKJ6AcljhBhQNosHRBY +RpSzxixT6dAU8pmIVmCsSX0xCVniV9MoA/LS37ht9RvRMnSRnFyLOErYp6RtEMQ7djt aUJw== X-Gm-Message-State: ALKqPwd2jnCiuvqIemp7nx7C4kgN2lsU+AcTdYCMEpMjN+p/sdNWSb6V +9efbExBk/eTPqYp6i5bJ1Vnqg== X-Received: by 2002:a17:902:bc84:: with SMTP id bb4-v6mr8067728plb.84.1526624802876; Thu, 17 May 2018 23:26:42 -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 b72-v6sm14157432pfm.69.2018.05.17.23.26.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 23:26:42 -0700 (PDT) From: Bjorn Andersson To: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Andy Gross , 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 Subject: [PATCH v3 1/3] scsi: ufs: Extract devfreq registration Date: Thu, 17 May 2018 23:26:36 -0700 Message-Id: <20180518062638.31777-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518062638.31777-1-bjorn.andersson@linaro.org> References: <20180518062638.31777-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") Also switch to use DEVFREQ_GOV_SIMPLE_ONDEMAND constant. Reviewed-by: Chanwoo Choi Signed-off-by: Bjorn Andersson --- Changes since v2: - Use DEVFREQ_GOV_SIMPLE_ONDEMAND, per Chanwoo's recommendation - Picked up Chanwoo's R-b 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 00e79057f870..f04902a066cb 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1287,6 +1287,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, + DEVFREQ_GOV_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; @@ -6439,16 +6459,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; }