Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1787196pxu; Sun, 13 Dec 2020 03:30:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbNa/X2y/sWImHpVZxJU2zh/SXv+nLBHFY+UrFInx4nbqF4jGNJ5UN846DV55MHb8Zxyy7 X-Received: by 2002:a17:906:f0d0:: with SMTP id dk16mr18430037ejb.144.1607859052588; Sun, 13 Dec 2020 03:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607859052; cv=none; d=google.com; s=arc-20160816; b=yGyRwAcKzkpRdbTf9V15MIYo+nkDEa+yWwdngptAIn7pSuSSY4p+59gCuHO7Ea96Uk ijL7EBCsVAhz5rVXzPSyHJjTl9vej6KFuaWXCL+e1JyYmFXQ+vHh//DyvtrTxPQzVG8l Ol7RoSZJjHWR4tdstijvTIpjC8B0c69DoBhJ/0iYbybRnpoPdM/bCnRMhFxT6qxaeEDp 3drr2N/Ld+NwX10qV6yGd92N/ii/tG8/iteTvI3rV7RwHDlItti1uCUMrsxIFRnqsQai jDCc4fe1eccrwLN7hTSEqadggp2aJjYpRqeByu/p6m3siMiHFTEJwuwo3KPqz9IDNMZQ dY4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=orV6Jiq3kXB0bcDgP4wZM6ASqt9ALseXlLi8MU8P7Ns=; b=f6HFjm4QAB1/VXk/cSovtvpue9porKKltAEDdQLJx1/dkXVvh6zEzIDb6H70k/xx5d 3ey6K2iGDKBHqDmflxFpAdLkGO9p5IqcxAxRaDg/wI0F6D6G+uXUkBp/K8/iHWNT1jxJ MTfaMwOkpTAWcyqDVPb35n4VCOyho6+hHGvkJeKNTQ4jAGh5scnq88Lk3oxgnjdfT/Ct Cv33pF8NyKMltoBo4TkYk1jaXczd36FyUJwv21oKFt2noUqAuz9mjuRTc3F5qUby2+Fz 74ea0Jh6jQXt4p4s0ILKEJSaH+m2dLEudFpl7Nz3LSXUOIEeQ1gcsxVhafxE/ZQjMFdk mcnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Y/Sb4BbQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id b8si8205414edx.538.2020.12.13.03.29.48; Sun, 13 Dec 2020 03:30:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Y/Sb4BbQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2405663AbgLKVTu (ORCPT + 99 others); Fri, 11 Dec 2020 16:19:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393412AbgLKVTN (ORCPT ); Fri, 11 Dec 2020 16:19:13 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BF4DC06179C for ; Fri, 11 Dec 2020 13:18:14 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id u18so15227317lfd.9 for ; Fri, 11 Dec 2020 13:18:14 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=orV6Jiq3kXB0bcDgP4wZM6ASqt9ALseXlLi8MU8P7Ns=; b=Y/Sb4BbQENjqsYlg1fDVvuON5YE+C4L3JZGFp1VhKJkJjAeDP0tezXoP49VoxIsmLZ DrlCyH1yE+w1cfnsNG0PpnmwkIrPegtOCAy7zlnQ9D+17sdPJ/x1Ed1LQy0UncQV6LXO 3ZtWXbXDho2IQG+gr9MkG8PGe+oH2rOEOExWl0bgRd6yA1g4jm1VYJJt3/3mHMSLdLNw in+HIWdSQx4MxjXqBclslBFEW0kGjLFkqoBHjY76G6kdZOZOtJQNa6i26eA3gT/bWxrm rvP65YF8jRpa4y1i92b6F4Q9O7ISNwN8zLScKxppeyWPU6xmAoCOwIy60OjtqqcQ0HgY L2Sw== 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:mime-version:content-transfer-encoding; bh=orV6Jiq3kXB0bcDgP4wZM6ASqt9ALseXlLi8MU8P7Ns=; b=sC3zNeMmTtwvNMLzm2lPg4dmwKfgRgXjYGKbfch3FjuDzL2aGzGO5XPJeLup8LZe3/ cA42ShDABdy9veCqDuOuaPJTMOsowdrf2orWUyZ5sj+p5drilAqo1bqrCITmtSGkRMOJ DdsmKrJ+lo8ofSlbUNhH5KVgg2s78MoVMBw1Hc9FrWzq44tQOJjnxx7teY/PedC+q7EF 3iuecbh5skDbW4XTf+vi7rT0f/RH0Sn4xNOXHKe2dlHgZKYQRpqLKIat9WmgJzWjPQQp GtDaREqSmby1+ckktRyf8rtED6foix4Y9roGtEcp03ybVIGcr2IL/N9acQNEY1r5D1HX H9+Q== X-Gm-Message-State: AOAM531LiKBd1wEmZPHWD2cQprQOoNCB1x1iYqSg906+lfGGQJsDYMbZ XYnIQNguT8lqL/zhOfqZLhNv/g== X-Received: by 2002:a19:f60b:: with SMTP id x11mr5758697lfe.156.1607721492841; Fri, 11 Dec 2020 13:18:12 -0800 (PST) Received: from localhost ([31.134.121.151]) by smtp.gmail.com with ESMTPSA id g190sm833904lfd.72.2020.12.11.13.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 13:18:12 -0800 (PST) From: Sam Protsenko To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , John Stultz , Andy Shevchenko Subject: [PATCH v3 2/2] usb: dwc3: drd: Improve dwc3_get_extcon() style Date: Fri, 11 Dec 2020 23:19:16 +0200 Message-Id: <20201211211916.6259-3-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201211211916.6259-1-semen.protsenko@linaro.org> References: <20201211211916.6259-1-semen.protsenko@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit c73b41955ee4 ("usb: dwc3: drd: Avoid error when extcon is missing") changed the code flow in dwc3_get_extcon() function, leading to unnecessary if-branch. This patch does housekeeping by reworking the code for obtaining extcon device from the "port" node. While at it, add the comment from mentioned code block, explaining how checking the port availability helps to avoid the misleading error. Signed-off-by: Sam Protsenko Cc: Andy Shevchenko --- Changes in v3: - Split patch into two patches: logic diff and style diff drivers/usb/dwc3/drd.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 312a4d060e80..eaf389d3f3c5 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -441,8 +441,8 @@ static int dwc3_drd_notifier(struct notifier_block *nb, static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) { struct device *dev = dwc->dev; - struct device_node *np_phy, *np_conn; - struct extcon_dev *edev; + struct device_node *np_phy; + struct extcon_dev *edev = NULL; const char *name; if (device_property_read_bool(dev, "extcon")) @@ -462,18 +462,22 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) return edev; } + /* + * Try to get extcon device from USB PHY controller's "port" node. + * Check if it has the "port" node first, to avoid printing the error + * message from underlying code, as it's a valid case: extcon device + * (and "port" node) may be missing in case of "usb-role-switch" or OTG + * mode. + */ np_phy = of_parse_phandle(dev->of_node, "phys", 0); - if (of_graph_is_present(np_phy)) - np_conn = of_graph_get_remote_node(np_phy, -1, -1); - else - np_conn = NULL; + if (of_graph_is_present(np_phy)) { + struct device_node *np_conn; - if (np_conn) - edev = extcon_find_edev_by_node(np_conn); - else - edev = NULL; - - of_node_put(np_conn); + np_conn = of_graph_get_remote_node(np_phy, -1, -1); + if (np_conn) + edev = extcon_find_edev_by_node(np_conn); + of_node_put(np_conn); + } of_node_put(np_phy); return edev; -- 2.29.2