mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: gregkh@linuxfoundation.org, linus.walleij@linaro.org,
	gnurou@gmail.com, wsa@the-dreams.de, sameo@linux.intel.com,
	lee.jones@linaro.org, johan@kernel.org, daniel.baluta@intel.com,
	laurentiu.palcu@intel.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-i2c@vger.kernel.org
Subject: Re: [PATCH v5 4/4] gpio: add support for the Diolan DLN-2 USB GPIO driver
Date: Sat, 20 Sep 2014 04:48:47 +0200	[thread overview]
Message-ID: <201409200448.48180.arnd@arndb.de> (raw)
In-Reply-To: <1411158165-25794-5-git-send-email-octavian.purdila@intel.com>

On Friday 19 September 2014, Octavian Purdila wrote:
> +struct dln2_gpio_pin {
> +	__le16 pin;
> +} __packed;

This does not need to be marked packed, since it is never embedded in another
structure.

> +struct dln2_gpio_pin_val {
> +	__le16 pin;
> +	u8 value;
> +} __packed;

It's enough here to mark just the 'pin' member as packed.

> +static int dln2_gpio_get_pin_count(struct platform_device *pdev)
> +{
> +	int ret;
> +	__le16 count;
> +	int len = sizeof(count);
> +
> +	ret = dln2_transfer(pdev, DLN2_GPIO_GET_PIN_COUNT, NULL, 0, &count,
> +			    &len);

You must not do a USB transaction on stack memory.

> +static int dln2_gpio_pin_cmd(struct dln2_gpio *dln2, int cmd, unsigned pin)
> +{
> +	struct dln2_gpio_pin req = {
> +		.pin = cpu_to_le16(pin),
> +	};
> +
> +	return dln2_transfer(dln2->pdev, cmd, &req, sizeof(req), NULL, NULL);
> +}

Same here

> +static int dln2_gpio_pin_val(struct dln2_gpio *dln2, int cmd, unsigned int pin)
> +{
> +	int ret;
> +	struct dln2_gpio_pin req = {
> +		.pin = cpu_to_le16(pin),
> +	};
> +	struct dln2_gpio_pin_val rsp;

And here.

> +static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
> +				  unsigned debounce)
> +{
> +	struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
> +	struct {
> +		__le32 duration;
> +	} __packed req = {
> +		.duration = cpu_to_le32(debounce),
> +	};
> +
> +	return dln2_transfer(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE,
> +			     &req, sizeof(req), NULL, NULL);
> +}

Here you also have a strange __packed attribute that makes no sense
for a local variable, in addition to the stack problem.

I think the only correct way to handle these is to add a dynamic
allocation of an entire page for the DMA, which can probably be
part of the dln2_transfer function so you don't have to do it
in each caller.

	Arnd

  reply	other threads:[~2014-09-20  2:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19 20:22 [PATCH v5 0/4] mfd: add support for Diolan DLN-2 Octavian Purdila
2014-09-19 20:22 ` [PATCH v5 1/4] mfd: add support for Diolan DLN-2 devices Octavian Purdila
2014-09-24 10:48   ` Johan Hovold
2014-09-24 13:36     ` Octavian Purdila
2014-09-24 13:54       ` Johan Hovold
2014-09-24 14:54         ` Octavian Purdila
2014-09-24 15:07           ` Johan Hovold
2014-09-24 15:22             ` Octavian Purdila
2014-09-25 10:25               ` Octavian Purdila
2014-09-25 10:30                 ` Johan Hovold
2014-09-25 10:41                   ` Octavian Purdila
2014-09-25 10:43                     ` Johan Hovold
2014-09-19 20:22 ` [PATCH v5 2/4] i2c: add support for Diolan DLN-2 USB-I2C adapter Octavian Purdila
2014-09-24 10:58   ` Johan Hovold
2014-09-19 20:22 ` [PATCH v5 3/4] gpiolib: add irq_not_threaded flag to gpio_chip Octavian Purdila
2014-09-24  8:54   ` Linus Walleij
2014-09-24 11:01     ` Johan Hovold
2014-09-19 20:22 ` [PATCH v5 4/4] gpio: add support for the Diolan DLN-2 USB GPIO driver Octavian Purdila
2014-09-20  2:48   ` Arnd Bergmann [this message]
2014-09-20  6:32     ` Octavian Purdila
2014-09-24 12:39   ` Johan Hovold

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=201409200448.48180.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=daniel.baluta@intel.com \
    --cc=gnurou@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=laurentiu.palcu@intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=octavian.purdila@intel.com \
    --cc=sameo@linux.intel.com \
    --cc=wsa@the-dreams.de \
    /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

Powered by JetHome