linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Gustavo Pimentel <Gustavo.Pimentel@synopsys.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	dmaengine@vger.kernel.org,
	Derek Kiernan <derek.kiernan@xilinx.com>,
	Dragan Cvetic <dragan.cvetic@xilinx.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: [RESEND PATCH v3 1/5] misc: Add Synopsys DesignWare xData IP driver
Date: Tue, 2 Feb 2021 18:07:58 +0100	[thread overview]
Message-ID: <YBmG7qgIDYIveDfX@kroah.com> (raw)
In-Reply-To: <2c70018d5965c171c15870638ee717fe5f9483f6.1612284945.git.gustavo.pimentel@synopsys.com>

On Tue, Feb 02, 2021 at 05:56:34PM +0100, Gustavo Pimentel wrote:
> Add Synopsys DesignWare xData IP driver. This driver enables/disables
> the PCI traffic generator module pertain to the Synopsys DesignWare
> prototype.
> 
> Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> ---
>  drivers/misc/dw-xdata-pcie.c | 379 +++++++++++++++++++++++++++++++++++++++++++

You are adding sysfs entries but you do not have any Documentation/ABI/
entries for us to be able to properly review this code :(

> +static ssize_t sysfs_write_show(struct kobject *kobj,
> +				struct kobj_attribute *attr, char *buf)
> +{
> +	struct device *dev = kobj2device(kobj);
> +	struct pci_dev *pdev = device2pci_dev(dev);
> +	struct dw_xdata *dw = pci_get_drvdata(pdev);
> +	u64 rate;
> +
> +	dw_xdata_perf(dw, &rate, true);
> +	return sprintf(buf, "%llu MB/s\n", rate);

sysfs_emit()

> +}
> +
> +static ssize_t sysfs_write_store(struct kobject *kobj,
> +				 struct kobj_attribute *attr, const char *buf,
> +				 size_t count)
> +{
> +	struct device *dev = kobj2device(kobj);
> +	struct pci_dev *pdev = device2pci_dev(dev);
> +	struct dw_xdata *dw = pci_get_drvdata(pdev);
> +
> +	pci_dbg(pdev, "xData: requested write transfer\n");
> +	dw_xdata_start(dw, true);
> +
> +	return count;
> +}
> +
> +struct kobj_attribute sysfs_write_attr = __ATTR(write, 0644,
> +						sysfs_write_show,
> +						sysfs_write_store);

__ATTR_RW() please

> +
> +static ssize_t sysfs_read_show(struct kobject *kobj,
> +			       struct kobj_attribute *attr, char *buf)
> +{
> +	struct device *dev = kobj2device(kobj);
> +	struct pci_dev *pdev = device2pci_dev(dev);
> +	struct dw_xdata *dw = pci_get_drvdata(pdev);
> +	u64 rate;
> +
> +	dw_xdata_perf(dw, &rate, false);
> +	return sprintf(buf, "%llu MB/s\n", rate);

sysfs_emit()

> +}
> +
> +static ssize_t sysfs_read_store(struct kobject *kobj,
> +				struct kobj_attribute *attr, const char *buf,
> +				size_t count)
> +{
> +	struct device *dev = kobj2device(kobj);
> +	struct pci_dev *pdev = device2pci_dev(dev);
> +	struct dw_xdata *dw = pci_get_drvdata(pdev);
> +
> +	pci_dbg(pdev, "xData: requested read transfer\n");
> +	dw_xdata_start(dw, false);
> +
> +	return count;
> +}
> +
> +struct kobj_attribute sysfs_read_attr = __ATTR(read, 0644,
> +					       sysfs_read_show,
> +					       sysfs_read_store);

__ATTR_RW()

> +
> +static ssize_t sysfs_stop_store(struct kobject *kobj,
> +				struct kobj_attribute *attr, const char *buf,
> +				size_t count)
> +{
> +	struct device *dev = kobj2device(kobj);

Wait, what???

Why are you creating "raw" kobjects here?  This is a device, use device
attributes.  Use DEVICE_ATTR_RW() for all of the above.

Who reviewed this thing???

> +	struct pci_dev *pdev = device2pci_dev(dev);
> +	struct dw_xdata *dw = pci_get_drvdata(pdev);
> +
> +	pci_dbg(pdev, "xData: requested stop any transfer\n");
> +	dw_xdata_stop(dw);
> +
> +	return count;
> +}
> +
> +struct kobj_attribute sysfs_stop_attr = __ATTR(stop, 0644,
> +					       NULL,
> +					       sysfs_stop_store);
> +
> +static int dw_xdata_pcie_probe(struct pci_dev *pdev,
> +			       const struct pci_device_id *pid)
> +{
> +	const struct dw_xdata_pcie_data *pdata = (void *)pid->driver_data;
> +	struct device *dev = &pdev->dev;
> +	struct dw_xdata *dw;
> +	u64 addr;
> +	int err;
> +
> +	/* Enable PCI device */
> +	err = pcim_enable_device(pdev);
> +	if (err) {
> +		pci_err(pdev, "enabling device failed\n");
> +		return err;
> +	}
> +
> +	/* Mapping PCI BAR regions */
> +	err = pcim_iomap_regions(pdev, BIT(pdata->rg_bar), pci_name(pdev));
> +	if (err) {
> +		pci_err(pdev, "xData BAR I/O remapping failed\n");
> +		return err;
> +	}
> +
> +	pci_set_master(pdev);
> +
> +	/* Allocate memory */
> +	dw = devm_kzalloc(&pdev->dev, sizeof(*dw), GFP_KERNEL);
> +	if (!dw)
> +		return -ENOMEM;
> +
> +	/* Data structure initialization */
> +	dw->rg_region.vaddr = pcim_iomap_table(pdev)[pdata->rg_bar];
> +	if (!dw->rg_region.vaddr)
> +		return -ENOMEM;
> +
> +	dw->rg_region.vaddr += pdata->rg_off;
> +	dw->rg_region.paddr = pdev->resource[pdata->rg_bar].start;
> +	dw->rg_region.paddr += pdata->rg_off;
> +	dw->rg_region.sz = pdata->rg_sz;
> +
> +	dw->max_wr_len = pcie_get_mps(pdev);
> +	dw->max_wr_len >>= 2;
> +
> +	dw->max_rd_len = pcie_get_readrq(pdev);
> +	dw->max_rd_len >>= 2;
> +
> +	dw->pdev = pdev;
> +
> +	writel(0x0, &(__dw_regs(dw)->RAM_addr));
> +	writel(0x0, &(__dw_regs(dw)->RAM_port));
> +
> +	addr = dw->rg_region.paddr + DW_XDATA_EP_MEM_OFFSET;
> +	writel(lower_32_bits(addr), &(__dw_regs(dw)->addr_lsb));
> +	writel(upper_32_bits(addr), &(__dw_regs(dw)->addr_msb));
> +	pci_dbg(pdev, "xData: target address = 0x%.16llx\n", addr);
> +
> +	pci_dbg(pdev, "xData: wr_len=%zu, rd_len=%zu\n",
> +		dw->max_wr_len * 4, dw->max_rd_len * 4);
> +
> +	err = sysfs_create_file(&dev->kobj, &sysfs_write_attr.attr);
> +	if (err)
> +		return err;
> +
> +	err = sysfs_create_file(&dev->kobj, &sysfs_read_attr.attr);
> +	if (err)
> +		return err;
> +
> +	err = sysfs_create_file(&dev->kobj, &sysfs_stop_attr.attr);
> +	if (err)
> +		return err;

By manually creating sysfs files, you just raced with userspace and lost
horribly.

Please never do that, use an attribute group and have the driver core
automatically create/remove your files for you.

Big hint, if you ever find yourself calling sysfs_* in a driver, you are
doing something wrong.

thanks,

greg k-h

  reply	other threads:[~2021-02-02 17:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 16:56 [RESEND PATCH v3 0/5] misc: Add Add Synopsys DesignWare xData IP driver Gustavo Pimentel
2021-02-02 16:56 ` [RESEND PATCH v3 1/5] misc: " Gustavo Pimentel
2021-02-02 17:07   ` Greg Kroah-Hartman [this message]
2021-02-02 16:56 ` [RESEND PATCH v3 2/5] misc: Add Synopsys DesignWare xData IP driver to Makefile Gustavo Pimentel
2021-02-02 16:56 ` [RESEND PATCH v3 3/5] misc: Add Synopsys DesignWare xData IP driver to Kconfig Gustavo Pimentel
2021-02-08  7:34   ` Leon Romanovsky
2021-02-08  9:02     ` Gustavo Pimentel
2021-02-02 16:56 ` [RESEND PATCH v3 4/5] Documentation: misc-devices: Add Documentation for dw-xdata-pcie driver Gustavo Pimentel
2021-02-02 16:56 ` [RESEND PATCH v3 5/5] MAINTAINERS: Add Synopsys xData IP driver maintainer Gustavo Pimentel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YBmG7qgIDYIveDfX@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=Gustavo.Pimentel@synopsys.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=corbet@lwn.net \
    --cc=derek.kiernan@xilinx.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=dragan.cvetic@xilinx.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).