mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Amber Kao <amber.kao@ite.com.tw>
Cc: Jeson Yang <jeson.yang@ite.com.tw>,
	Yaode Fang <Yaode.Fang@ite.com.tw>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Bling Chiang <Bling.Chiang@ite.com.tw>,
	Eric Su <Eric.Su@ite.com.tw>, Doreen Lin <doreen.lin@ite.com.tw>
Subject: Re: [PATCH v4 2/2] usb: typec: ucsi: Add ITE IT8851/IT8853 Type-C PD controller driver
Date: Tue, 21 Jul 2026 12:05:44 +0300	[thread overview]
Message-ID: <al82aJzFzx44oXTf@kuha> (raw)
In-Reply-To: <20260717-ucsi-itepd-v4-2-f3ba5addd0df@ite.com.tw>

Hi Amber,

This looks okay otherwise, but I have to ask about the i2c reads and
writes..

> +static int itepd_read_reg(struct itepd *itepd, u8 reg, void *data, u32 len)
> +{
> +	struct i2c_client *client = itepd->client;
> +	struct i2c_msg msg[2];
> +	u8 *tx_buf, *rx_buf;
> +	int ret;
> +
> +	tx_buf = kzalloc(1, GFP_KERNEL);
> +	if (!tx_buf)
> +		return -ENOMEM;

That looks completely unnecessary. You really don't need to allocate
local buffer for one byte.

> +	rx_buf = kzalloc(len, GFP_KERNEL);
> +	if (!rx_buf) {
> +		kfree(tx_buf);
> +		return -ENOMEM;
> +	}

I'm not sure about this either.

> +	tx_buf[0] = reg;
> +
> +	msg[0].addr	= client->addr;
> +	msg[0].flags	= 0;
> +	msg[0].len	= 1;
> +	msg[0].buf	= tx_buf;
> +
> +	msg[1].addr	= client->addr;
> +	msg[1].flags	= I2C_M_RD;
> +	msg[1].len	= len;
> +	msg[1].buf	= rx_buf;
> +
> +	mutex_lock(&itepd->i2c_lock);
> +	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
> +	mutex_unlock(&itepd->i2c_lock);
> +	if (ret < 0) {
> +		dev_err_ratelimited(&client->dev, "reg 0x%02x read failed: %d\n",
> +				    reg, ret);
> +		goto out_free;
> +	}
> +	if (ret != ARRAY_SIZE(msg)) {
> +		ret = -EIO;
> +		goto out_free;
> +	}
> +
> +	memcpy(data, rx_buf, len);

This whole thing looks almost like SMBus Block Read protocol. Can't
you just use
i2c_smbus_read_i2c_block_data(client, reg, len, data)?

> +	ret = 0;
> +
> +out_free:
> +	kfree(rx_buf);
> +	kfree(tx_buf);
> +	return ret;
> +}
> +
> +static int itepd_write_reg(struct itepd *itepd, u8 reg, const void *data, u32 len)
> +{
> +	struct i2c_client *client = itepd->client;
> +	struct i2c_msg msg[1];
> +	u8 *tx_buf;
> +	int ret;
> +
> +	tx_buf = kzalloc(len + 1, GFP_KERNEL);
> +	if (!tx_buf)
> +		return -ENOMEM;
> +
> +	tx_buf[0] = reg;
> +	memcpy(tx_buf + 1, data, len);
> +
> +	msg[0].addr	= client->addr;
> +	msg[0].flags	= 0;
> +	msg[0].len	= len + 1;
> +	msg[0].buf	= tx_buf;
> +
> +	mutex_lock(&itepd->i2c_lock);
> +	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
> +	mutex_unlock(&itepd->i2c_lock);

i2c_smbus_write_i2c_block_data(client, reg, len, data)?

> +	if (ret < 0) {
> +		dev_err_ratelimited(&client->dev, "reg 0x%02x write failed: %d\n",
> +				    reg, ret);
> +		goto out_free;
> +	}
> +	if (ret != ARRAY_SIZE(msg)) {
> +		ret = -EIO;
> +		goto out_free;
> +	}
> +
> +	ret = 0;
> +
> +out_free:
> +	kfree(tx_buf);
> +	return ret;
> +}

Thanks,

-- 
heikki

      reply	other threads:[~2026-07-21  9:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  9:59 [PATCH v4 0/2] usb: typec: ucsi: Add ITE IT8851/IT8853 support Amber Kao
2026-07-17  9:59 ` [PATCH v4 1/2] dt-bindings: usb: Add ITE IT8851/IT8853 Type-C PD controllers Amber Kao
2026-07-19  7:37   ` Krzysztof Kozlowski
2026-07-17  9:59 ` [PATCH v4 2/2] usb: typec: ucsi: Add ITE IT8851/IT8853 Type-C PD controller driver Amber Kao
2026-07-21  9:05   ` Heikki Krogerus [this message]

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=al82aJzFzx44oXTf@kuha \
    --to=heikki.krogerus@linux.intel.com \
    --cc=Bling.Chiang@ite.com.tw \
    --cc=Eric.Su@ite.com.tw \
    --cc=Yaode.Fang@ite.com.tw \
    --cc=amber.kao@ite.com.tw \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=doreen.lin@ite.com.tw \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeson.yang@ite.com.tw \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh@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

all inboxes | Powered by JetHome®