Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2625338imm; Thu, 11 Oct 2018 13:23:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Ox2JC0+hKSpXHvV0mF7X5MS4W6ONJqn5M2EUCQLCvTNw5HwvGSM1YZGomCNoYKI2O46bH X-Received: by 2002:a63:5021:: with SMTP id e33-v6mr2715182pgb.306.1539289390749; Thu, 11 Oct 2018 13:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539289390; cv=none; d=google.com; s=arc-20160816; b=aa1QinW7wJVGKWcG3/qqmI+5f2j32QGd9uBVbrGcTOvQjwFPx6zEjpc3XPqA7jeejZ KCwn1fwDJzkOPkWusnBCCY9oa9ylDYQDO/5Bu+pYSUXkPWp7H6Hzkljl8b1IOrugHLnA 0QCsx06DVSWYyjVadvs0L4esUQQN0FwuXLL28aD4eWM8Ny/IfdAhYAWlqSh3UVdTveqn CgcWeWRoC/YGahSop7gkTOFc7PHYXn73HXI1DO5kOMkqdR6YpxoLBbJPJJPxsR0Xybji UYaPsA0MXKi9yHDm5EJYnFUNjMXUfW64SRCuMyxO+W6zEPHtI3krkleImjSLblms/tL1 hbIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=XLb5dhnivT+1/4hU4EU2dDLTGyDtSL2UFXUJdu0lDAg=; b=uSZr/G38gACPZXt3thlRIfg5L1r36VkDCOIcebv/W7JkRAAmR3xuhGe37tWHnGR0Ee +dV1DeBvhixVfV1GUm9IsY0TafRvDXRZhZ/h0WhkLfKzuWMfkimrGWArmAjrs8JdJnCQ 5AHGtAZoTQ45igtWbIE14+Gqq+FclyUS+nsxAip9TvWz7XesQwxTmtVPKuh9h9wJhC+M TwF6VaaEPobbpNns3k/l0RH9f6I3hbKkKtVhnkb0qPKGxI2pd6GXjc4/19sxKxnxjgPv dDN8YHvr2bvNWGku5FRocHLNJ5CgwbKlSrDDvEEtvIRX/9cmLLO/1MTNka084/avYf6A Z9Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hJKBuyaW; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si31753496pfb.89.2018.10.11.13.22.55; Thu, 11 Oct 2018 13:23:10 -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=@chromium.org header.s=google header.b=hJKBuyaW; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbeJLDug (ORCPT + 99 others); Thu, 11 Oct 2018 23:50:36 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:43459 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbeJLDuf (ORCPT ); Thu, 11 Oct 2018 23:50:35 -0400 Received: by mail-vs1-f65.google.com with SMTP id w85so9821744vsa.10 for ; Thu, 11 Oct 2018 13:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XLb5dhnivT+1/4hU4EU2dDLTGyDtSL2UFXUJdu0lDAg=; b=hJKBuyaWyh0E4D4M3tnP8avrPcUZU/XcFLeq18kDwqy0EFpE+QiQZ7OB076MVcqXlB jBVrRR3hDnb2WfFoQ+vcbMjumf4+XcHxOn7NxDJaSXWdvLd29GHVrAvJnqhsgqlAclEt xiVA0Aw2lIt77grRG0z/RylNQIFbsz6RRn8DA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XLb5dhnivT+1/4hU4EU2dDLTGyDtSL2UFXUJdu0lDAg=; b=ANokSrnHtEkMS1XKeTEzxKJTAjBnbtdFwsMgSXhhJBkywN3/Jdg3Yth4pZxUojs8FC 0HK9fbotDJRojtXAjdDxBmpKki6F86tSVtXZ42njPBwcAJ7TEXRdSt6eYySfeujLM6L2 JgVSalU4pTgnvwe4Cvnk9sP90THSiFdi/FGymRmQ+n1L7Yo9j2jBd+Pljr3Q7NeG3C1y YSnzM/r/CvKjrGTcZg1VQGxcY7ZlPuVDIazsg8uSA+dMNjINICFqr75sQ/sFN9Fj3wb8 FYTCKibwZTxpCKBLgSnmxBOsukrOtjMcFFrYkrxgFpsYh7YO5644R2K7D2dkBsPFrk8O /Xbw== X-Gm-Message-State: ABuFfoivdGR6BEzzv/+qgPggVOHy5uj35jq75TUmVZ+Iz/WRUa+ECIlH DuZ5Mqi2DESXvUkHIx52JzhndGllGvE= X-Received: by 2002:ab0:14e4:: with SMTP id f33-v6mr1460637uae.122.1539289302826; Thu, 11 Oct 2018 13:21:42 -0700 (PDT) Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com. [209.85.217.48]) by smtp.gmail.com with ESMTPSA id u72-v6sm3658246vku.26.2018.10.11.13.21.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 13:21:41 -0700 (PDT) Received: by mail-vs1-f48.google.com with SMTP id r83so9843811vsc.4 for ; Thu, 11 Oct 2018 13:21:41 -0700 (PDT) X-Received: by 2002:a67:1141:: with SMTP id 62-v6mr1299123vsr.213.1539289301181; Thu, 11 Oct 2018 13:21:41 -0700 (PDT) MIME-Version: 1.0 References: <1539261196-14550-1-git-send-email-cang@codeaurora.org> In-Reply-To: <1539261196-14550-1-git-send-email-cang@codeaurora.org> From: Doug Anderson Date: Thu, 11 Oct 2018 13:21:28 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] scsi: ufs: make UFS Tx lane1 clock optional for QCOM platforms To: cang@codeaurora.org Cc: subhashj@codeaurora.org, Asutosh Das , Vivek Gautam , Evan Green , Rajendra Nayak , Vinayak Holikatti , jejb@linux.vnet.ibm.com, "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-arm-msm , venkatg@codeaurora.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, Oct 11, 2018 at 5:33 AM Can Guo wrote: > static int ufs_qcom_host_clk_get(struct device *dev, > - const char *name, struct clk **clk_out) > + const char *name, struct clk **clk_out, bool optional) > { > struct clk *clk; > int err = 0; > > clk = devm_clk_get(dev, name); > - if (IS_ERR(clk)) { > + if (clk == ERR_PTR(-EPROBE_DEFER)) { > + err = -EPROBE_DEFER; > + dev_warn(dev, "required clock %s hasn't probed yet, err %d\n", > + name, err); > + } else if (IS_ERR(clk)) { > + if (optional) > + return 0; Change this function to: static int ufs_qcom_host_clk_get(struct device *dev, const char *name, struct clk **clk_out, bool optional) { struct clk *clk; int err; clk = devm_clk_get(dev, name); if (!IS_ERR(clk)) { *clk_out = clk; return 0; } err = PTR_ERR(clk); if (optional && err == -ENOENT) { *clk_out = NULL; return 0; } if (err != -EPROBE_DEFER) dev_err(dev, "failed to get %s err %d", name, err); return err; } Specifically: * Typically it just spams the log to print something when you see an -EPROBE_DEFER. * If a clock is optional you should only consider things a success only if "-ENOENT" was returned. All other errors should be considered fatal. * If a clock is optional it's slightly cleaner to set *clk_out to NULL. I know you're initting global data that happened to already be NULL by default, but it still feels nice for the abstraction of the function to do this. * Please don't pass __func__ to your error messages. > err = PTR_ERR(clk); > dev_err(dev, "%s: failed to get %s err %d", > __func__, name, err); > @@ -113,10 +119,10 @@ static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host) > if (!host->is_lane_clks_enabled) > return; > > - if (host->hba->lanes_per_direction > 1) > + if (host->tx_l1_sync_clk) Remove this "if". Always call clk_disable_unprepare() which will be a no-op if "host->tx_l1_sync_clk" is NULL. clk_disable_unprepare() is a no-op for NULL clocks by design specifically to make code like this cleaner. > clk_disable_unprepare(host->tx_l1_sync_clk); > clk_disable_unprepare(host->tx_l0_sync_clk); > - if (host->hba->lanes_per_direction > 1) > + if (host->rx_l1_sync_clk) Remove this "if". Always call clk_disable_unprepare() which will be a no-op if "host->rx_l1_sync_clk" is NULL. clk_disable_unprepare() is a no-op for NULL clocks by design specifically to make code like this cleaner. > clk_disable_unprepare(host->rx_l1_sync_clk); > clk_disable_unprepare(host->rx_l0_sync_clk); > > @@ -141,12 +147,14 @@ static int ufs_qcom_enable_lane_clks(struct ufs_qcom_host *host) > if (err) > goto disable_rx_l0; > > - if (host->hba->lanes_per_direction > 1) { > + if (host->rx_l1_sync_clk) { Remove this "if". Always call ufs_qcom_host_clk_enable(). The clk_prepare_enable() inside ufs_qcom_host_clk_enable() will be a no-op if "host->rx_l1_sync_clk" is NULL and will return 0 (no error). > err = ufs_qcom_host_clk_enable(dev, "rx_lane1_sync_clk", > host->rx_l1_sync_clk); > if (err) > goto disable_tx_l0; > + } > > + if (host->tx_l1_sync_clk) { Remove this "if". Always call ufs_qcom_host_clk_enable(). The clk_prepare_enable() inside ufs_qcom_host_clk_enable() will be a no-op if "host->tx_l1_sync_clk" is NULL and will return 0 (no error). -Doug