linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Ye Xiang <xiang.ye@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Matthias Kaehlcke <mka@chromium.org>, Lee Jones <lee@kernel.org>,
	Wolfram Sang <wsa@kernel.org>, Tyrone Ting <kfting@nuvoton.com>,
	Mark Brown <broonie@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	linux-gpio@vger.kernel.org
Cc: srinivas.pandruvada@intel.com, heikki.krogerus@linux.intel.com,
	andriy.shevchenko@linux.intel.com, sakari.ailus@linux.intel.com,
	zhifeng.wang@intel.com, wentong.wu@intel.com,
	lixu.zhang@intel.com
Subject: Re: [PATCH v4 1/5] mfd: Add support for Intel LJCA device
Date: Thu, 9 Mar 2023 13:53:28 +0100	[thread overview]
Message-ID: <097d1742-1aa8-fc0b-db11-3571ea49383d@suse.com> (raw)
In-Reply-To: <20230309071100.2856899-2-xiang.ye@intel.com>



On 09.03.23 08:10, Ye Xiang wrote:

> +static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, unsigned int obuf_len,
> +			   void *ibuf, unsigned int *ibuf_len, bool wait_ack, unsigned long timeout)

Why do you make ibuf_len a pointer?

> +{
> +	struct ljca_dev *dev = usb_get_intfdata(stub->intf);
> +	u8 flags = LJCA_CMPL_FLAG;
> +	struct ljca_msg *header;
> +	unsigned int msg_len = sizeof(*header) + obuf_len;
> +	int actual;
> +	int ret;
> +
> +	if (msg_len > LJCA_MAX_PACKET_SIZE)
> +		return -EINVAL;
> +
> +	if (wait_ack)
> +		flags |= LJCA_ACK_FLAG;
> +
> +	header = kmalloc(msg_len, GFP_KERNEL);
> +	if (!header)
> +		return -ENOMEM;
> +
> +	header->type = stub->type;
> +	header->cmd = cmd;
> +	header->flags = flags;
> +	header->len = obuf_len;
> +
> +	if (obuf)
> +		memcpy(header->data, obuf, obuf_len);
> +
> +	dev_dbg(&dev->intf->dev, "send: type:%d cmd:%d flags:%d len:%d\n", header->type,
> +		header->cmd, header->flags, header->len);
> +
> +	usb_autopm_get_interface(dev->intf);
> +	if (!dev->started) {

Memory leak in error case. You must free header.

> +		ret = -ENODEV;
> +		goto error_put;
> +	}
> +
> +	mutex_lock(&dev->mutex);
> +	stub->cur_cmd = cmd;
> +	stub->ipacket.ibuf = ibuf;
> +	stub->ipacket.ibuf_len = ibuf_len;
> +	stub->acked = false;
> +	ret = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->out_ep), header, msg_len,
> +			   &actual, LJCA_USB_WRITE_TIMEOUT_MS);
> +	kfree(header);
> +	if (ret) {
> +		dev_err(&dev->intf->dev, "bridge write failed ret:%d\n", ret);
> +		goto error_unlock;
> +	}
> +
> +	if (actual != msg_len) {
> +		dev_err(&dev->intf->dev, "bridge write length mismatch (%d vs %d)\n", msg_len,
> +			actual);
> +		ret = -EINVAL;
> +		goto error_unlock;
> +	}
> +
> +	if (wait_ack) {
> +		ret = wait_event_timeout(dev->ack_wq, stub->acked, msecs_to_jiffies(timeout));
> +		if (!ret) {
> +			dev_err(&dev->intf->dev, "acked wait timeout\n");
> +			ret = -ETIMEDOUT;

If that triggers, you may have a pending URB.
You must kill it.

> +			goto error_unlock;
> +		}
> +	}
> +
> +	stub->ipacket.ibuf = NULL;
> +	stub->ipacket.ibuf_len = NULL;
> +	ret = 0;
> +error_unlock:
> +	mutex_unlock(&dev->mutex);
> +error_put:
> +	usb_autopm_put_interface(dev->intf);
> +	return ret;
> +}


> +static int ljca_i2c_stub_init(struct ljca_dev *dev, struct ljca_i2c_descriptor *desc)
> +{
> +	struct ljca_i2c_info *i2c_info;
> +	struct ljca_stub *stub;
> +	int ret;
> +	int i;
> +
> +	stub = ljca_stub_alloc(dev, LJCA_I2C_STUB, size_mul(desc->num, sizeof(*i2c_info)));
> +	if (IS_ERR(stub))
> +		return PTR_ERR(stub);
> +
> +	i2c_info = ljca_priv(stub);
> +
> +	for (i = 0; i < desc->num; i++) {
> +		struct mfd_cell cell = {};
> +
> +		i2c_info[i].ljca = &stub->ljca;
> +		i2c_info[i].id = desc->info[i].id;
> +		i2c_info[i].capacity = desc->info[i].capacity;
> +		i2c_info[i].intr_pin = desc->info[i].intr_pin;
> +
> +		cell.name = "ljca-i2c";
> +		cell.platform_data = &i2c_info[i];
> +		cell.pdata_size = sizeof(i2c_info[i]);
> +
> +		if (i < ARRAY_SIZE(ljca_acpi_match_i2cs))
> +			cell.acpi_match = &ljca_acpi_match_i2cs[i];
> +
> +		ret = ljca_add_mfd_cell(dev, &cell);
> +		if (ret)
> +			return ret;

What happens to stub in the error case?

> +	}
> +
> +	return 0;
> +}


> +
> +static void ljca_disconnect(struct usb_interface *intf)
> +{
> +	struct ljca_dev *dev = usb_get_intfdata(intf);
> +
> +	ljca_stop(dev);

What prevents restarting the device here?

> +	mfd_remove_devices(&intf->dev);
> +	ljca_stub_cleanup(dev);
> +	ljca_delete(dev);
> +}
> +
> +static int ljca_suspend(struct usb_interface *intf, pm_message_t message)
> +{
> +	struct ljca_dev *dev = usb_get_intfdata(intf);
> +
> +	ljca_stop(dev);
> +	return 0;
> +}
> +
> +static int ljca_resume(struct usb_interface *intf)
> +{
> +	struct ljca_dev *dev = usb_get_intfdata(intf);
> +
> +	return ljca_start(dev);

So here you report errors, but at the same time you set "started"
even if errors occur.

	Regards
		Oliver

  parent reply	other threads:[~2023-03-09 12:53 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  7:10 [PATCH v4 0/5] Add Intel LJCA device driver Ye Xiang
2023-03-09  7:10 ` [PATCH v4 1/5] mfd: Add support for Intel LJCA device Ye Xiang
2023-03-09  7:49   ` Greg Kroah-Hartman
2023-03-09  9:10     ` Ye, Xiang
2023-03-09  9:26       ` Greg Kroah-Hartman
2023-03-09 10:16         ` Ye, Xiang
2023-03-09  7:52   ` Greg Kroah-Hartman
2023-03-09  9:31     ` Ye, Xiang
2023-03-09  9:41       ` Greg Kroah-Hartman
2023-03-09 10:06         ` Andi Shyti
2023-03-09 15:45           ` Ye, Xiang
2023-03-09 15:58             ` Greg Kroah-Hartman
2023-03-09 17:42               ` Ye, Xiang
2023-03-09  7:56   ` Arnd Bergmann
2023-03-09 10:00     ` Ye, Xiang
2023-03-09 11:03     ` Mark Brown
2023-03-09 11:30       ` Arnd Bergmann
2023-03-09 12:53   ` Oliver Neukum [this message]
2023-03-10  4:14     ` Ye, Xiang
2023-03-13 13:27       ` Oliver Neukum
2023-03-14  7:15         ` Ye, Xiang
2023-03-09  7:10 ` [PATCH v4 2/5] gpio: Add support for Intel LJCA USB GPIO driver Ye Xiang
2023-03-09 13:40   ` Oliver Neukum
2023-03-09 13:52     ` Andy Shevchenko
2023-03-09 14:06       ` Greg Kroah-Hartman
2023-03-09 14:18       ` Linus Walleij
2023-03-09 14:36         ` Greg Kroah-Hartman
2023-03-09 14:48         ` Arnd Bergmann
2023-03-09 17:37           ` Oliver Neukum
2023-03-09 17:30       ` Oliver Neukum
2023-03-10  5:01     ` Ye, Xiang
2023-03-10  7:11       ` Greg Kroah-Hartman
2023-03-10  7:39         ` Ye, Xiang
2023-03-10  7:53           ` Greg Kroah-Hartman
2023-03-10  8:59             ` Ye, Xiang
2023-03-11 12:13   ` Krzysztof Kozlowski
2023-03-12 15:40     ` Ye, Xiang
2023-03-09  7:10 ` [PATCH v4 3/5] i2c: Add support for Intel LJCA USB I2C driver Ye Xiang
2023-03-09  7:10 ` [PATCH v4 4/5] spi: Add support for Intel LJCA USB SPI driver Ye Xiang
2023-03-09  7:11 ` [PATCH v4 5/5] Documentation: Add ABI doc for attributes of LJCA device Ye Xiang

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=097d1742-1aa8-fc0b-db11-3571ea49383d@suse.com \
    --to=oneukum@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kfting@nuvoton.com \
    --cc=lee@kernel.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-spi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lixu.zhang@intel.com \
    --cc=mka@chromium.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=srinivas.pandruvada@intel.com \
    --cc=wentong.wu@intel.com \
    --cc=wsa@kernel.org \
    --cc=xiang.ye@intel.com \
    --cc=zhifeng.wang@intel.com \
    /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).