Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp125427ybi; Fri, 26 Jul 2019 07:09:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxs7lL+TW1Hx6wCZGcQMcMXMqAuHwu4UMQYYPw+1R7Hmz1mqtSM0kY/VXMmwIz57hUpfSTn X-Received: by 2002:a17:90a:c68c:: with SMTP id n12mr99884651pjt.29.1564150171518; Fri, 26 Jul 2019 07:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564150171; cv=none; d=google.com; s=arc-20160816; b=nlvVurOw/xk0T9pnvEPYL/beFUNlSIGlvB482v1J3ilaNKrr/WDcwB3Y7g5hp72rOj f7I+6jogm/nc4VM1HcVFsFyrk9Mn8su8iDuDv/oRuiXG1o5jNcELCIOlPCttpn/I1V6a +n89X3H2y6tvqqePH3f+03tGPyW6Qh6DoliIv4gtf7zo/xNMv9cNama9YHKugxuyepQC KOkUS6wFh3LAoRsfcexNiBpmlgE/7+9zOQ+/55jJk93X1WJVgn+vVsuM6XpCvwkECxqR vvzXMPprHAvN2l+sSqfEj8no79Bj11byoPFsoza8t+JudXaS4YRUsSKMaq03EAIwE5Kk rNrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7u0LxhIYFNkeBtA6htQ02bwwpXTQHIdneE4KFPcGEzc=; b=asy28FijoCTKF4Qoyw8KvdhUO2kF5Mi488BZ3HGKatWXLX/gM6oxOQFdj3mXJrT0Kj XL6ZxRkAWz8b8cnt+6Hine0ihuD5RkVFaEYmxiNs0PqJPWmrvd7amvSWTicgB7xdT3yH q9OYZ/4D7qZUM0Yaak5hS9qqRhNhR/I18CsbgN2RqaCvhlIfZyqItwWo+QHUhBE/9z1q Dn2FtTBORj4tmffxwSUHRYLXhZxqyRvyBhRf/hqQFf/x3SAhW34vG1wWHRHK3ji3CbpM 3IYJqGkS9Oz7KUfpby8L5H8/kypsK/s7DaWsGhOXVs6ASltqHVtLzVZv1+8WuXhm+epj X1kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VL/IqECo"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si20315094pfo.108.2019.07.26.07.09.16; Fri, 26 Jul 2019 07:09:31 -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=@kernel.org header.s=default header.b="VL/IqECo"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727437AbfGZOGj (ORCPT + 99 others); Fri, 26 Jul 2019 10:06:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:44000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbfGZOGi (ORCPT ); Fri, 26 Jul 2019 10:06:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 38E3621743; Fri, 26 Jul 2019 14:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564149997; bh=6LfqjPN06gwOLWMwiAbSXnJ6+TV+cegwJWjCipI2Wyk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VL/IqECoYI4eYvfJUGVC1aH6YMKwuhRuSkd291Mfe4ePuIBtEbWsJpwY2NQU1NjLW 2Rn4DKNkoGzdQnlpJyyofZmQFUZQh57Li8DDVikI4X8Nc81RkOUsB58txa8gOBlM5X 04i/RLTXM+4sJp1aAUGCYBC64di1c2CfwqVd6QVk= Date: Fri, 26 Jul 2019 16:06:35 +0200 From: Greg KH To: Pierre-Louis Bossart Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, tiwai@suse.de, broonie@kernel.org, vkoul@kernel.org, jank@cadence.com, srinivas.kandagatla@linaro.org, slawomir.blauciak@intel.com, Sanyog Kale Subject: Re: [RFC PATCH 04/40] soundwire: intel: add debugfs register dump Message-ID: <20190726140635.GB8767@kroah.com> References: <20190725234032.21152-1-pierre-louis.bossart@linux.intel.com> <20190725234032.21152-5-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190725234032.21152-5-pierre-louis.bossart@linux.intel.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 25, 2019 at 06:39:56PM -0500, Pierre-Louis Bossart wrote: > Add debugfs file to dump the Intel SoundWire registers > > Credits: this patch is based on an earlier internal contribution by > Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah. The main change > is the use of scnprintf to avoid known issues with snprintf. > > Signed-off-by: Pierre-Louis Bossart > --- > drivers/soundwire/intel.c | 115 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 115 insertions(+) > > diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c > index 317873bc0555..aeadc341c0a3 100644 > --- a/drivers/soundwire/intel.c > +++ b/drivers/soundwire/intel.c > @@ -6,6 +6,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -16,6 +17,7 @@ > #include > #include > #include "cadence_master.h" > +#include "bus.h" > #include "intel.h" > > /* Intel SHIM Registers Definition */ > @@ -98,6 +100,7 @@ struct sdw_intel { > struct sdw_cdns cdns; > int instance; > struct sdw_intel_link_res *res; > + struct dentry *fs; > }; > > #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns) > @@ -161,6 +164,115 @@ static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask) > return -EAGAIN; > } > > +/* > + * debugfs > + */ > + > +#define RD_BUF (2 * PAGE_SIZE) > + > +static ssize_t intel_sprintf(void __iomem *mem, bool l, > + char *buf, size_t pos, unsigned int reg) > +{ > + int value; > + > + if (l) > + value = intel_readl(mem, reg); > + else > + value = intel_readw(mem, reg); > + > + return scnprintf(buf + pos, RD_BUF - pos, "%4x\t%4x\n", reg, value); > +} > + > +static ssize_t intel_reg_read(struct file *file, char __user *user_buf, > + size_t count, loff_t *ppos) > +{ > + struct sdw_intel *sdw = file->private_data; > + void __iomem *s = sdw->res->shim; > + void __iomem *a = sdw->res->alh; > + char *buf; > + ssize_t ret; > + int i, j; > + unsigned int links, reg; > + > + buf = kzalloc(RD_BUF, GFP_KERNEL); > + if (!buf) > + return -ENOMEM; > + > + links = intel_readl(s, SDW_SHIM_LCAP) & GENMASK(2, 0); > + > + ret = scnprintf(buf, RD_BUF, "Register Value\n"); > + ret += scnprintf(buf + ret, RD_BUF - ret, "\nShim\n"); > + > + for (i = 0; i < 4; i++) { > + reg = SDW_SHIM_LCAP + i * 4; > + ret += intel_sprintf(s, true, buf, ret, reg); > + } > + > + for (i = 0; i < links; i++) { > + ret += scnprintf(buf + ret, RD_BUF - ret, "\nLink%d\n", i); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLSCAP(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS0CM(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS1CM(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS2CM(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS3CM(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PCMSCAP(i)); > + > + for (j = 0; j < 8; j++) { > + ret += intel_sprintf(s, false, buf, ret, > + SDW_SHIM_PCMSYCHM(i, j)); > + ret += intel_sprintf(s, false, buf, ret, > + SDW_SHIM_PCMSYCHC(i, j)); > + } > + > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PDMSCAP(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_IOCTL(i)); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTMCTL(i)); > + } > + > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKEEN); > + ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKESTS); > + > + ret += scnprintf(buf + ret, RD_BUF - ret, "\nALH\n"); > + for (i = 0; i < 8; i++) > + ret += intel_sprintf(a, true, buf, ret, SDW_ALH_STRMZCFG(i)); > + > + ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); > + kfree(buf); > + > + return ret; > +} > + > +static const struct file_operations intel_reg_fops = { > + .open = simple_open, > + .read = intel_reg_read, > + .llseek = default_llseek, > +}; DEFINE_SIMPLE_ATTRIBUTE()? > + > +static void intel_debugfs_init(struct sdw_intel *sdw) > +{ > + struct dentry *root = sdw->cdns.bus.debugfs; > + > + if (!root) > + return; > + > + sdw->fs = debugfs_create_dir("intel-sdw", root); > + if (IS_ERR_OR_NULL(sdw->fs)) { > + dev_err(sdw->cdns.dev, "debugfs root creation failed\n"); No, come on, don't do that. I've been sweeping the kernel tree to remove this anti-pattern. The debugfs core will print an error if you got something wrong, just call the function and move on, you NEVER need to check the return value of a debugfs call. thanks, greg k-h