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: 10408269 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 2CA1060353 for ; Fri, 18 May 2018 06:27:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EDF928868 for ; Fri, 18 May 2018 06:27:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13C752886B; Fri, 18 May 2018 06:27:48 +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 B76372886A for ; Fri, 18 May 2018 06:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751452AbeERG1d (ORCPT ); Fri, 18 May 2018 02:27:33 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:44229 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752044AbeERG0n (ORCPT ); Fri, 18 May 2018 02:26:43 -0400 Received: by mail-pl0-f65.google.com with SMTP id e6-v6so3970727plt.11 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=MYn1hdScHTuqtFaParxDUjkeZ4jeBj+FWbP1rV8J0pdsq4L/9/K0nt8BfxrZB2nIAV aPT/tjVJHhFuaaSJrqTNNqjBGrXUhINw06Q+6BTLrjBeGprtxzB0quBlv692McwPJY9F 8yyJRDy8z36NAF692veN+QARMNcW6nxJm0m8eMoEwNtJb6vK+cmZoNEM5GPzeEE0V0bJ UIz7IQ4hcLpPFZAbGz6hJfAa7LdKFxQUTYI7OfugxQKE4GVE7ejAxyFSHkCaGzc1dh6R VVp1yy+DGJykwGdFPEyUJJjNm0JJT9X1frM1KKg2ghZhqS84cbXjiVJa1VV4PVfcVPLX bd0w== X-Gm-Message-State: ALKqPwfSyEfL5dJfBVG+NmXREyeBwVH+rPoqA93gux6IVLPPfHyZo8qL Ht9WH5BSkUP3OOE8isE7b6LY2A== X-Google-Smtp-Source: AB8JxZoG59+qyP3fkIHNIBVvfa/z5/fr6+rA0Dtv15uX32HFgb6W2lNqn+NFMh95QJWj+KLOCWGzIQ== 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-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") 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(-) 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; }