* [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer
@ 2024-05-31 9:34 Jean Delvare
2024-06-04 1:12 ` Andi Shyti
2024-06-26 10:39 ` Wolfram Sang
0 siblings, 2 replies; 3+ messages in thread
From: Jean Delvare @ 2024-05-31 9:34 UTC (permalink / raw)
To: Linux I2C
It is good practice to check that the underlying adapter supports
I2C transfers before attempting them. The i2c core would eventually
return an error, but it's more efficient to fail early.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Not sure about that one, opinions welcome.
drivers/i2c/i2c-dev.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
--- linux-6.9.orig/drivers/i2c/i2c-dev.c
+++ linux-6.9/drivers/i2c/i2c-dev.c
@@ -139,6 +139,10 @@ static ssize_t i2cdev_read(struct file *
struct i2c_client *client = file->private_data;
+ /* Adapter must support I2C transfers */
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ return -EOPNOTSUPP;
+
if (count > 8192)
count = 8192;
@@ -163,6 +167,10 @@ static ssize_t i2cdev_write(struct file
char *tmp;
struct i2c_client *client = file->private_data;
+ /* Adapter must support I2C transfers */
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ return -EOPNOTSUPP;
+
if (count > 8192)
count = 8192;
@@ -238,6 +246,10 @@ static noinline int i2cdev_ioctl_rdwr(st
u8 __user **data_ptrs;
int i, res;
+ /* Adapter must support I2C transfers */
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ return -EOPNOTSUPP;
+
data_ptrs = kmalloc_array(nmsgs, sizeof(u8 __user *), GFP_KERNEL);
if (data_ptrs == NULL) {
kfree(msgs);
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer
2024-05-31 9:34 [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer Jean Delvare
@ 2024-06-04 1:12 ` Andi Shyti
2024-06-26 10:39 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2024-06-04 1:12 UTC (permalink / raw)
To: Jean Delvare; +Cc: Linux I2C
Hi Jean,
On Fri, May 31, 2024 at 11:34:07AM +0200, Jean Delvare wrote:
> It is good practice to check that the underlying adapter supports
> I2C transfers before attempting them. The i2c core would eventually
> return an error, but it's more efficient to fail early.
>
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
Looks good to me:
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Thanks,
Andi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer
2024-05-31 9:34 [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer Jean Delvare
2024-06-04 1:12 ` Andi Shyti
@ 2024-06-26 10:39 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2024-06-26 10:39 UTC (permalink / raw)
To: Jean Delvare; +Cc: Linux I2C
[-- Attachment #1: Type: text/plain, Size: 348 bytes --]
On Fri, May 31, 2024 at 11:34:07AM GMT, Jean Delvare wrote:
> It is good practice to check that the underlying adapter supports
> I2C transfers before attempting them. The i2c core would eventually
> return an error, but it's more efficient to fail early.
>
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-26 10:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31 9:34 [PATCH] i2c: dev: Check for I2C_FUNC_I2C before calling i2c_transfer Jean Delvare
2024-06-04 1:12 ` Andi Shyti
2024-06-26 10:39 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox