From patchwork Tue Apr 24 00:20:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134036 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1607525lji; Mon, 23 Apr 2018 17:21:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49IJVVrES/IatUoFvsJgoZzx8uIbiSj7X0lI/jS1E2T/EDmD7hkQT9W5SUpopekWHRJMULN X-Received: by 10.98.204.220 with SMTP id j89mr21741786pfk.182.1524529266777; Mon, 23 Apr 2018 17:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524529266; cv=none; d=google.com; s=arc-20160816; b=hUuJBxtJGz0ceMaZC1/Ptu2vcNJnuJ+gY6xKujNTMsDzSuQ4J0TL2t1GJ0lATn4/Ot MVhqtasI8CLmxtltDTxhqCcMpp47zXLDpd5Y4MVkUIt0tBJs5W7E+gWzKJ6iTdWCtzrP gBOAa249UPxDESly+/JtVcdUn03y9leUOWWUXeTX71174Qdk/pdLECsBpMQ/wxg5QtWc NgKi2A/2eBCMUFc4iLyGlmxWZiKOS8jfXlOGFZJSHJDBF2uUGMfQ7iLul9MsVv+IjuMN 1Lv/IUzGLJj2mVvGSdsbFXpnWcEwBpTnJlbnkhX4n0ps2ViRidMWr3MColO6M2+rExv7 8g2w== 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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=dUYSBk+jexprAAlXcHp2CeC00dnIvRKdx+6dXrJ/jQ97LP/kopbDgOe55NQQEBqiGR eIPBnDcFeOn+2U8Zj75UVcl49RQBHideBKIBJHIP6J7osCSymDAaMNn9sGippF91jxgM wd2CFhcl9/Pl+cm7fmDnOZRWxyu4Z9CV6XghjbIMRLFH2uBzSNOCxGD3tndDt3EL3Pup QG+0vmasRljH0h8cIZOXOgjAvKBnuY+LG4AqYSyAtFSkdRSd/C44uR3VUwP06mcskPXa 02GXVTgkeZmVQdkaD4TnRvon0Wk+4dfkSdTSE9WbZv5IgxiHGKgVFzizsahTni7ApB7c b7HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J2s69Ubs; 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 h17si12369555pfj.178.2018.04.23.17.21.06; Mon, 23 Apr 2018 17:21:06 -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=J2s69Ubs; 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 S932739AbeDXAVE (ORCPT + 29 others); Mon, 23 Apr 2018 20:21:04 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:44519 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932674AbeDXAUW (ORCPT ); Mon, 23 Apr 2018 20:20:22 -0400 Received: by mail-pf0-f195.google.com with SMTP id p15so10681759pff.11 for ; Mon, 23 Apr 2018 17:20:22 -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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=J2s69UbsahGMzxJIdQWi4bfO6OZ8ercD2J74i+LalmAZKU3tOwlIPdZBrzYQzoaJcN kkviA5WBDjS8yL333Gj/4GLx9MTFd0GByph3zAW6HYQNVDZJAICyQHGqEWIculhRMw3E xdBnUggCuw3Q4OkG0p50nxH9E26jGZ0c/zp2U= 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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=oGi0veqlAv844ohc8ZzS1TEhUv9SIW0N1oRucRajVM/0+uR7+YU87idJvtCsJ/FpS1 Jy+UR4X96Io+rSTJPOAKQIUG5bGqX38JXhMD3Gu6sbDtgbtlBUkr4eNptDnfpT7rYu// Uj7Zuy5ws96tGUxAJFAhMbNzmunK3K12Xtxty8ymKZEgI15/DqUXXJemczKkyQMzZn3B bozurtlzYn2hdhOWW5eSCOxBxOzItXgaZtW6t5kaQ4wKD3ga5CcVF3A4D4iBcQc9QC5g HZeNW2kMH+e5oUxZjlIkJQBT9EtCU0WID1+QylMu/hrb6cU/jHcm9qKfQm/OCXESj0Ye FXPA== X-Gm-Message-State: ALQs6tDAZ1jMQU68ikIMQHvuN6AC42oVdWqaQ6NVeRn7AccP+K8Qbdjl 75MixMXy7nhLqXohnU9CWN2Fkw== X-Received: by 10.98.14.7 with SMTP id w7mr21747324pfi.50.1524529222072; Mon, 23 Apr 2018 17:20:22 -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 p6sm26669845pfk.104.2018.04.23.17.20.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 17:20:21 -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 2/3] scsi: ufs: Extract devfreq registration Date: Mon, 23 Apr 2018 17:20:15 -0700 Message-Id: <20180424002016.9205-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180424002016.9205-1-bjorn.andersson@linaro.org> References: <20180424002016.9205-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") Signed-off-by: Bjorn Andersson --- drivers/scsi/ufs/ufshcd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.16.2 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; }