Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5488665pxb; Wed, 26 Jan 2022 13:13:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyueC8/vKTO+EQVg3whIJNboVMB9SieHS9A8jiaAQ2MN/wW6ShIP5PusO9RCOBbCNH0TjEe X-Received: by 2002:a63:ed17:: with SMTP id d23mr486908pgi.543.1643231633444; Wed, 26 Jan 2022 13:13:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643231633; cv=none; d=google.com; s=arc-20160816; b=GbvrL8SsKGVa4G9Mm2ckNWMEwAzlzi+i1SqAb3sYxbUjg5dbLHHrdYvlJ7t5Io0jRd PIEMTbTGKFHTGHQvRTZIcv+ild7pgPeTnLWH4Co8Yfd8yGNZq6z/o8G7/BvdNsInXpbq tLeze4LF6wXPibaFsiVKkl72NM/JkU+G1ufS0TnhxS7N7TiBb5ChPfkEX4zQ8aL3NZ1U q+xgy8IJcQlnXJj3btt8ri3XR99f3IDamhGbHPF656d/l9qKJ1UliwsQsefZXYjO04uB 3UtZaWK3RWmlsqLvjioQFNniEmsPwK7RL3rVAbUuDxeHMxh6zUdAY81H0dJF2IE96v+z 7xXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rovIzsfaotBXYU7XHH0CF+1sq0HIAI5bt7R/6PSFWXA=; b=h0xzPykmmWlYxkXuyu51MWaQaV5MnUBdl1C7JpSen0ONTG6NRusx2e5xsl/lMcblJx vy26Pk6OCwuI7laE2trmMB3DpZUuOIOtpFwXlyTerHAGC4QJq76uYU5jJ/aj0mokyQRz bSswfsG/d3AXluqt1yAo7ttuZ6bEeXMY6CA/lCdy4GiSqd0lB8aF1jjoTgg33WEv+pf0 pNLS4H6T7PA7d5Kfjn4L8UxENZt5GGJ9GGdcOxmBBL6Y07WfDneCtqM4sUqY3DGhlE1f NZXRWlpdBGVWqCAlFoarOSljmq2PP+muFqIXHiLJRkkFvA/Q9+v3P19qVcdEIIxbKqdG bzMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dCRkNEFI; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j11si381711pfj.322.2022.01.26.13.13.41; Wed, 26 Jan 2022 13:13:53 -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=@linuxfoundation.org header.s=korg header.b=dCRkNEFI; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241289AbiAZM2s (ORCPT + 99 others); Wed, 26 Jan 2022 07:28:48 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:51160 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241262AbiAZM2s (ORCPT ); Wed, 26 Jan 2022 07:28:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1256CB81B99; Wed, 26 Jan 2022 12:28:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E1F9C340E6; Wed, 26 Jan 2022 12:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643200125; bh=JDYmW4ZoybujXBTRgOaP0WReuDW0MypIno9+z1llHEk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dCRkNEFIanjThujf/WhTxahyIZPC4c+gC4npeXVQR+JFK123EvRnIVP2h5DhvvXw5 kHUBDQJ6c14hH5wttiaUjfDuKj25a1hx/DMKGlKtN7FGiYnNwI0oFfxkKIuUHrYYZf 9HCTMNc2IYKdcNXBWMjhAJaR1/0X+HTbnmDayCYQ= Date: Wed, 26 Jan 2022 13:28:42 +0100 From: Greg Kroah-Hartman To: Sean Anderson Cc: linux-usb@vger.kernel.org, Heikki Krogerus , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: ulpi: Add debugfs support Message-ID: References: <20220114163947.790078-1-sean.anderson@seco.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 11:28:26AM -0500, Sean Anderson wrote: > > > On 1/23/22 6:27 AM, Greg Kroah-Hartman wrote: > > On Fri, Jan 14, 2022 at 11:39:47AM -0500, Sean Anderson wrote: > >> This adds a debugfs file for ULPI devices which contains a dump of their > >> registers. This is useful for debugging basic connectivity problems. The > >> file is created in ulpi_register because many devices will never have a > >> driver bound (as they are managed in hardware by the USB controller > >> device). > >> > >> Signed-off-by: Sean Anderson > >> --- > >> > >> drivers/usb/common/ulpi.c | 100 ++++++++++++++++++++++++++++++++++-- > >> include/linux/ulpi/driver.h | 3 ++ > >> 2 files changed, 99 insertions(+), 4 deletions(-) > >> > >> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c > >> index 4169cf40a03b..a39c48e04013 100644 > >> --- a/drivers/usb/common/ulpi.c > >> +++ b/drivers/usb/common/ulpi.c > >> @@ -13,6 +13,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> #include > >> @@ -228,9 +229,64 @@ static int ulpi_read_id(struct ulpi *ulpi) > >> return 0; > >> } > >> > >> +static int __maybe_unused ulpi_regs_read(struct seq_file *seq, void *data) > >> +{ > >> + struct ulpi *ulpi = seq->private; > >> + > >> +#define ulpi_print(name, reg) do { \ > >> + int ret = ulpi_read(ulpi, reg); \ > >> + if (ret < 0) \ > >> + return ret; \ > >> + seq_printf(seq, name " %.02x\n", ret); \ > >> +} while (0) > >> + > >> + ulpi_print("Vendor ID Low ", ULPI_VENDOR_ID_LOW); > >> + ulpi_print("Vendor ID High ", ULPI_VENDOR_ID_HIGH); > >> + ulpi_print("Product ID Low ", ULPI_PRODUCT_ID_LOW); > >> + ulpi_print("Product ID High ", ULPI_PRODUCT_ID_HIGH); > >> + ulpi_print("Function Control ", ULPI_FUNC_CTRL); > >> + ulpi_print("Interface Control ", ULPI_IFC_CTRL); > >> + ulpi_print("OTG Control ", ULPI_OTG_CTRL); > >> + ulpi_print("USB Interrupt Enable Rising ", ULPI_USB_INT_EN_RISE); > >> + ulpi_print("USB Interrupt Enable Falling", ULPI_USB_INT_EN_FALL); > >> + ulpi_print("USB Interrupt Status ", ULPI_USB_INT_STS); > >> + ulpi_print("USB Interrupt Latch ", ULPI_USB_INT_LATCH); > >> + ulpi_print("Debug ", ULPI_DEBUG); > >> + ulpi_print("Scratch Register ", ULPI_SCRATCH); > >> + ulpi_print("Carkit Control ", ULPI_CARKIT_CTRL); > >> + ulpi_print("Carkit Interrupt Delay ", ULPI_CARKIT_INT_DELAY); > >> + ulpi_print("Carkit Interrupt Enable ", ULPI_CARKIT_INT_EN); > >> + ulpi_print("Carkit Interrupt Status ", ULPI_CARKIT_INT_STS); > >> + ulpi_print("Carkit Interrupt Latch ", ULPI_CARKIT_INT_LATCH); > >> + ulpi_print("Carkit Pulse Control ", ULPI_CARKIT_PLS_CTRL); > >> + ulpi_print("Transmit Positive Width ", ULPI_TX_POS_WIDTH); > >> + ulpi_print("Transmit Negative Width ", ULPI_TX_NEG_WIDTH); > >> + ulpi_print("Receive Polarity Recovery ", ULPI_POLARITY_RECOVERY); > >> + > >> + return 0; > >> +} > >> + > >> +static int __maybe_unused ulpi_regs_open(struct inode *inode, struct file *f) > >> +{ > >> + struct ulpi *ulpi = inode->i_private; > >> + > >> + return single_open(f, ulpi_regs_read, ulpi); > >> +} > >> + > >> +static const struct file_operations __maybe_unused ulpi_regs_ops = { > >> + .owner = THIS_MODULE, > >> + .open = ulpi_regs_open, > >> + .release = single_release, > >> + .read = seq_read, > >> + .llseek = seq_lseek > >> +}; > >> + > >> +static struct dentry *ulpi_root = (void *)-EPROBE_DEFER; > > > > There is no need for this variable, nor is there ever a need to set this > > to an error value like this. If you need to find the root, just look it > > up! > > The reason why it is set to a non-zero value is so that it doesn't get > coalesced with other zero-initialized static variables. That doesn't matter, you shouldn't need to initialize this. > >> + > >> static int ulpi_register(struct device *dev, struct ulpi *ulpi) > >> { > >> int ret; > >> + struct dentry *regs; > >> > >> ulpi->dev.parent = dev; /* needed early for ops */ > >> ulpi->dev.bus = &ulpi_bus; > >> @@ -245,16 +301,39 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi) > >> > >> ret = ulpi_read_id(ulpi); > >> if (ret) > >> - return ret; > >> + goto err_of; > >> > >> ret = device_register(&ulpi->dev); > >> if (ret) > >> - return ret; > >> + goto err_of; > >> + > >> + if (IS_ENABLED(CONFIG_DEBUG_FS)) { > > > > This check is not needed, the compiler will handle it all for your > > automatically. > > > >> + ulpi->root = debugfs_create_dir(dev_name(dev), ulpi_root); > >> + if (IS_ERR(ulpi->root)) { > > > > No need to check this, just keep moving on. debugfs return values > > shoudl NEVER be checked as your code should not care what happens. > > OK. The reason we have the above check is so we don't fail here because > if we don't have CONFIG_DEBUG_FS then debugfs_create_dir() will fail > with -ENODEV. That's fine, there is no need to check a debugfs call, and any result returned by a debugfs call can be passed to another debugfs call with no problems. thanks, greg k-h