lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 18 Sep 2013 09:11:05 -0700
From:	Joe Perches <joe@...ches.com>
To:	Michal Simek <michal.simek@...inx.com>
Cc:	linux-kernel@...r.kernel.org, monstr@...str.eu,
	Alan Tull <atull@...era.com>, Pavel Machek <pavel@....cz>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Dinh Nguyen <dinguyen@...era.com>,
	Philip Balister <philip@...ister.org>,
	Alessandro Rubini <rubini@...dd.com>,
	Mauro Carvalho Chehab <m.chehab@...sung.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Cesar Eduardo Barros <cesarb@...arb.net>,
	"David S. Miller" <davem@...emloft.net>,
	Stephen Warren <swarren@...dia.com>,
	Arnd Bergmann <arnd@...db.de>,
	David Brown <davidb@...eaurora.org>,
	Dom Cobley <popcornmix@...il.com>
Subject: Re: [RFC PATCH] fpga: Introduce new fpga subsystem

On Wed, 2013-09-18 at 17:56 +0200, Michal Simek wrote:
> This new subsystem should unify all fpga drivers which
> do the same things. Load configuration data to fpga
> or another programmable logic through common interface.
> It doesn't matter if it is MMIO device, gpio bitbanging,
> etc. connection. The point is to have the same
> inteface for these drivers.

Is this really a "driver".
Perhaps it's more of a core kernel function
and belongs in kernel.

> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c

The error messages are a little shouty with all
the unnecessary "!" uses.  

[]

> +/**
> + * fpga_mgr_read - Read data from fpga
> + * @mgr: Pointer to the fpga manager structure
> + * @buf: Pointer to the buffer location
> + * @count: Pointer to the number of copied bytes
> + *
> + * Function reads fpga bitstream and copy them to output buffer.
> + *
> + * Returns the number of bytes copied to @buf, a negative error number otherwise
> + */
> +static int fpga_mgr_read(struct fpga_manager *mgr, char *buf, ssize_t *count)
> +{
> +	int ret;
> +
> +	if (test_and_set_bit_lock(FPGA_MGR_DEV_BUSY, &mgr->flags))
> +		return -EBUSY;
> +
> +	if (!mgr->mops || !mgr->mops->read) {
> +		dev_err(mgr->dev,
> +			"Controller doesn't support read operations!\n");
> +		return -EPERM;
> +	}
> +
> +	if (mgr->mops->read_init) {
> +		ret = mgr->mops->read_init(mgr);
> +		if (ret) {
> +			dev_err(mgr->dev, "Failed in read-init!\n");
> +			return ret;
> +		}
> +	}
> +
> +	if (mgr->mops->read) {
> +		ret = mgr->mops->read(mgr, buf, count);
> +		if (ret) {
> +			dev_err(mgr->dev, "Failed to read firmware!\n");
> +			return ret;
> +		}
> +	}
> +
> +	if (mgr->mops->read_complete) {
> +		ret = mgr->mops->read_complete(mgr);
> +		if (ret) {
> +			dev_err(mgr->dev, "Failed in read-complete!\n");
> +			return ret;
> +		}
> +	}
> +
> +	clear_bit_unlock(FPGA_MGR_DEV_BUSY, &mgr->flags);
> +
> +	return 0;
> +}
> +
> +/**
> + * fpga_mgr_attr_read - Read data from fpga
> + * @dev: Pointer to the device structure
> + * @attr: Pointer to the device attribute structure
> + * @buf: Pointer to the buffer location
> + *
> + * Function reads fpga bitstream and copy them to output buffer
> + *
> + * Returns the number of bytes copied to @buf, a negative error number otherwise
> + */
> +static ssize_t fpga_mgr_attr_read(struct device *dev,
> +				   struct device_attribute *attr, char *buf)
> +{
> +	struct fpga_manager *mgr = dev_get_drvdata(dev);
> +	ssize_t count;
> +	int ret;
> +
> +	if (mgr && mgr->fpga_read)
> +		ret = mgr->fpga_read(mgr, buf, &count);
> +
> +	return ret == 0 ? count : -EPERM;

EPERM isn't the only error return from fpga_read.

> +}
> +
> +/**
> + * fpga_mgr_write - Write data to fpga
> + * @mgr: Pointer to the fpga manager structure
> + * @fw_name: Pointer to the buffer location with bistream firmware filename
> + *
> + * @buf contains firmware filename which is loading through firmware
> + * interface and passed to the fpga driver.
> + *
> + * Returns string lenght added to @fw_name, a negative error number otherwise
> + */
> +static int fpga_mgr_write(struct fpga_manager *mgr, const char *fw_name)
> +{
> +	int ret = 0;
> +	const struct firmware *fw;
> +
> +	if (!fw_name || !strlen(fw_name)) {
> +		dev_err(mgr->dev, "Firmware name is not specified!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!mgr->mops || !mgr->mops->write) {
> +		dev_err(mgr->dev,
> +			"Controller doesn't support write operations!\n");
> +		return -EPERM;

I think you should revisit the return codes.


> +/**
> + * fpga_mgr_attr_write - Write data to fpga
> + * @dev: Pointer to the device structure
> + * @attr: Pointer to the device attribute structure
> + * @buf: Pointer to the buffer location with bistream firmware filename
> + * @count: Number of characters in @buf
> + *
> + * @buf contains firmware filename which is loading through firmware
> + * interface and passed to the fpga driver.
> + *
> + * Returns string lenght added to @buf, a negative error number otherwise
> + */
> +static ssize_t fpga_mgr_attr_write(struct device *dev,
> +				   struct device_attribute *attr,
> +				   const char *buf, size_t count)
> +{
> +	struct fpga_manager *mgr = dev_get_drvdata(dev);
> +	int ret;
> +
> +	if (mgr && mgr->fpga_write)
> +		ret = mgr->fpga_write(mgr, buf);
> +
> +	return ret == 0 ? strlen(buf) : -EPERM;
> +}

Same -EPERM issue as read

> +	mgr = devm_kzalloc(&pdev->dev, sizeof(*mgr), GFP_KERNEL);
> +	if (!mgr) {
> +		dev_err(&pdev->dev, "Failed to alloc mgr struct!\n");

Unnecessary OOM message as there's a general dump_stack()
already done on any OOM without GFP_NOWARN

> diff --git a/include/linux/fpga.h b/include/linux/fpga.h
[]
> +struct fpga_manager {
> +	char name[48];

Maybe a #define instead of 48?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ