From patchwork Fri Dec 11 21:19:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 341982 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp920320jai; Fri, 11 Dec 2020 13:20:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwb0Sisz9D/2F6h7JHBVhkGZVIlXfrKU7Jv9lgpsHv4XjSZKArbVFdPEcAgznoi1Y9M+Jp0 X-Received: by 2002:a17:906:1f44:: with SMTP id d4mr12158969ejk.368.1607721617756; Fri, 11 Dec 2020 13:20:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607721617; cv=none; d=google.com; s=arc-20160816; b=Hj0vAcovISSSXL+qXn3MJxUE8Z4njXgAbuDXdw8drmF7jE/omioMQta3ozpFGCzrPI l3YH2NPNQZ56fHz7kwzszkwagctGlVIqgjclpq/CZggRBev3F4g4uBkaH2EWi0OgGnZd r23NqH9uTw1ah1NVqijaoqLENLu6Ue7xVGY9aXVeFkHDopsVBYBKnDXXf+MntqAjQyUe +4O2Ngv8ktQatdW1v/cvByIiSQ8L6NVTrPui1ikr0Uwo/EYapeBVNkAoL2+QpkZc5UV4 XhBBerAl9Bc/pgA00PbSybesb3xdpDtQzR+KW4MdV+QbEp4JQMhC2EI3+RagQjbvUFP4 jA/g== 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=aa7CDOWUsyiNiNIuP8HbiJ2mLSKEQEASjrZqXW//VhdpZlPbD3nASXyzD+l2/As2fz l8oYjU5DSH7DadwwePz4AVK2tKG3xCHapsLuxDL2HGGjkNohhFaWPFotGIs8kThpMxup Qj01c6rio818f42sDOCiX15poG6Jzdo5Fqi0BsW6PeJnxoKDx0dkQnutjuMFl21AOha9 IBtWHKHNR+o40cwgcE9G/9cOnQiW45BfMguiDWeQ6kA93uw2cTf+7LESzmKPzYD8woVv 1CSm57I3t+Wbmp69Xn0TOQhcwbtNsJBnlo+MpT7EXN4Db0fY4ZPNLB9GHuP6inyBJ7VN Jd+g== 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-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-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 gn38si5186169ejc.438.2020.12.11.13.20.17; Fri, 11 Dec 2020 13:20:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-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-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-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 S2405882AbgLKVTw (ORCPT + 4 others); Fri, 11 Dec 2020 16:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395504AbgLKVTN (ORCPT ); Fri, 11 Dec 2020 16:19:13 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6394C0617A6 for ; Fri, 11 Dec 2020 13:18:14 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id y19so15187531lfa.13 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=EzBmBVCNGTNCloBiZOvzIJVJ0lM14uPQzp+XtkiQ35Cl04lMniTWNFeNaCw7t6wUot mfiCdyq8xFedQdyjgmqrONkxE0bEo16ixGXicgkHFEt9P8Yacdi+sT7KSfPzDiDQOARb /1Kir5QcFsLx1hzrEXV/QR4DOB4j8FEl1OnHuflUQOS+hl0kjFHFQ7n0R2LIEvoYN077 jwQG05LMU8OeyEyGdXn9WWX7y0mHExIDr3DnQBH7jFER8MxBMzYnvIqWHi2UcBYsOhls uSV7EO5/T0fiNEz0oCuLPaoDEIEoC/DHhCw1gIZSur8CojIHgb3LduFfVuDcfaARfywB F1lQ== X-Gm-Message-State: AOAM532kIJhMTdl4t5O+BAvmxHk3LcNr89FhJLS6ucwQ5U0SBcwiel9l RD/PhqILADmD8WTkxi4ltKk24NWpyvlhPxA+v3Y= 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 Precedence: bulk List-ID: X-Mailing-List: linux-usb@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(-) -- 2.29.2 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;