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: 10408271 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 EA815602C2 for ; Fri, 18 May 2018 06:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBA6328868 for ; Fri, 18 May 2018 06:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF7922886B; Fri, 18 May 2018 06:27:50 +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 22FC028868 for ; Fri, 18 May 2018 06:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752291AbeERG1s (ORCPT ); Fri, 18 May 2018 02:27:48 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:45511 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752020AbeERG0n (ORCPT ); Fri, 18 May 2018 02:26:43 -0400 Received: by mail-pl0-f66.google.com with SMTP id bi12-v6so3968667plb.12 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=JrNH4oqd5FB3FlGFdXgkywR1Bk9dHGLKyw9vj08LoncOXbrMFn1cnAULafmEcGQwHC KfCq0rtFd7McMhmAoAxWQTXI7MHoNlMOSgF+a246qorsryUav7g5LYqQnzuwOFlCw3XZ cDsyOHvWY3fB+2sny/rJtlY03HhilF9g7NvBASeR7VM/8nwXqfn3Yn5ECIXxLtVjbpTF z57NNaCGjZwsp3SBGk/Ch2U36ZEa0Lx2kCI8hOStMh67BQyOc9SY+tmJaQwgseP5TB2J mNnFPT7vdxWxgrA5yLoQPmavaMY09wKpROfKXOQD3BAgLkLkOJE08iUnTdsWb1AH5SQA G3ig== X-Gm-Message-State: ALKqPwdJyDMCznrfzXs9GoQIyLJEOC5svQEFXTjdtPkg0GgAyYytU3l3 miI43Uw0w03FPA3lZQQBv3wacA== 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-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") 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; }