All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: fabrice.gasnier@foss.st.com
Cc: alexandre.torgue@foss.st.com, amelie.delaunay@foss.st.com,
	devicetree@vger.kernel.org, gregkh@linuxfoundation.org,
	heikki.krogerus@linux.intel.com,
	krzysztof.kozlowski+dt@linaro.org, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-usb@vger.kernel.org, robh+dt@kernel.org
Subject: Re: [PATCH 2/4] usb: typec: ucsi: stm32g0: add support for stm32g0 i2c controller
Date: Sat, 25 Jun 2022 08:37:49 +0200	[thread overview]
Message-ID: <f2e89d3a-f6ad-6fdc-1bd1-eb38f5a8f569@wanadoo.fr> (raw)
In-Reply-To: <20220624155413.399190-3-fabrice.gasnier@foss.st.com>

Le 24/06/2022 à 17:54, Fabrice Gasnier a écrit :
> STM32G0 provides an integrated USB Type-C and power delivery interface.
> It can be programmed with a firmware to handle UCSI protocol over I2C
> interface. A GPIO is used as an interrupt line.
> 
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier-rj0Iel/JR4NBDgjK7y7TUQ@public.gmane.org>
> ---
>   drivers/usb/typec/ucsi/Kconfig        |  10 ++
>   drivers/usb/typec/ucsi/Makefile       |   1 +
>   drivers/usb/typec/ucsi/ucsi_stm32g0.c | 218 ++++++++++++++++++++++++++
>   3 files changed, 229 insertions(+)
>   create mode 100644 drivers/usb/typec/ucsi/ucsi_stm32g0.c
> 

[...]

> +static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val,
> +				    size_t len)
> +{
> +	struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi);
> +	struct i2c_client *client = g0->client;
> +	struct i2c_msg msg[] = {
> +		{
> +			.addr	= client->addr,
> +			.flags  = 0,
> +		}
> +	};
> +	unsigned char *buf;
> +	int ret;
> +
> +	buf = kzalloc(len + 1, GFP_KERNEL);

Hi,

Nit: kmalloc() would be enough here, the whole buffer is written just a 
few lines after.

> +	if (!buf)
> +		return -ENOMEM;
> +
> +	buf[0] = offset;
> +	memcpy(&buf[1], val, len);
> +	msg[0].len = len + 1;
> +	msg[0].buf = buf;
> +
> +	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
> +	kfree(buf);
> +	if (ret != ARRAY_SIZE(msg)) {
> +		dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, buf[0], ret);

Use-after-free of buf.

> +
> +		return ret < 0 ? ret : -EIO;
> +	}
> +
> +	return 0;
> +}
> +

Just my 2c,
CJ

[...]

  reply	other threads:[~2022-06-25  6:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 15:54 [PATCH 0/4] usb: typec: ucsi: add support for stm32g0 Fabrice Gasnier
2022-06-24 15:54 ` [PATCH 1/4] dt-bindings: usb: typec: add bindings for stm32g0 controller Fabrice Gasnier
2022-06-24 16:16   ` Krzysztof Kozlowski
2022-06-27 14:21     ` Fabrice Gasnier
2022-06-28 10:28       ` Krzysztof Kozlowski
2022-06-28 17:01         ` Fabrice Gasnier
2022-06-29  5:54           ` Krzysztof Kozlowski
2022-07-01 10:04             ` Fabrice Gasnier
2022-07-04  7:55               ` Krzysztof Kozlowski
2022-07-04  9:08                 ` Fabrice Gasnier
2022-07-06  7:06                   ` Krzysztof Kozlowski
2022-06-24 15:54 ` [PATCH 2/4] usb: typec: ucsi: stm32g0: add support for stm32g0 i2c controller Fabrice Gasnier
2022-06-25  6:37   ` Christophe JAILLET [this message]
2022-06-27 13:17   ` Heikki Krogerus
2022-06-28  7:21     ` Fabrice Gasnier
2022-06-28  9:56       ` Heikki Krogerus
2022-06-24 15:54 ` [PATCH 3/4] usb: typec: ucsi: stm32g0: add bootloader support Fabrice Gasnier
2022-06-24 15:54 ` [PATCH 4/4] usb: typec: ucsi: stm32g0: add support for power management Fabrice Gasnier

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=f2e89d3a-f6ad-6fdc-1bd1-eb38f5a8f569@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.