* [PATCH] i2c: smbus: fix NULL function pointer dereference
@ 2024-04-26 6:44 Wolfram Sang
2024-04-26 7:28 ` Sergei Shtylyov
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Wolfram Sang @ 2024-04-26 6:44 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Wolfram Sang, Baruch Siach, linux-i2c, linux-kernel
Brauch reported an OOPS when using the designware controller as target
only. Target-only modes break the assumption of one transfer function
always being available. Fix this by always checking the pointer in
__i2c_transfer.
Reported-by: Baruch Siach <baruch@tkos.co.il>
Closes: https://lore.kernel.org/r/4269631780e5ba789cf1ae391eec1b959def7d99.1712761976.git.baruch@tkos.co.il
Fixes: 4b1acc43331d ("i2c: core changes for slave support")
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core-base.c | 12 ++++++------
drivers/i2c/i2c-core-smbus.c | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ff5c486a1dbb..db0d1ac82910 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2200,13 +2200,18 @@ static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs,
* Returns negative errno, else the number of messages executed.
*
* Adapter lock must be held when calling this function. No debug logging
- * takes place. adap->algo->master_xfer existence isn't checked.
+ * takes place.
*/
int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
{
unsigned long orig_jiffies;
int ret, try;
+ if (!adap->algo->master_xfer) {
+ dev_dbg(&adap->dev, "I2C level transfers not supported\n");
+ return -EOPNOTSUPP;
+ }
+
if (WARN_ON(!msgs || num < 1))
return -EINVAL;
@@ -2273,11 +2278,6 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
{
int ret;
- if (!adap->algo->master_xfer) {
- dev_dbg(&adap->dev, "I2C level transfers not supported\n");
- return -EOPNOTSUPP;
- }
-
/* REVISIT the fault reporting model here is weak:
*
* - When we get an error after receiving N bytes from a slave,
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index e3b96fc53b5c..a942c5306a4e 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -596,7 +596,7 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
break;
}
- if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
+ if (res != -EOPNOTSUPP)
goto trace;
/*
* Fall back to i2c_smbus_xfer_emulated if the adapter doesn't
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: smbus: fix NULL function pointer dereference
2024-04-26 6:44 [PATCH] i2c: smbus: fix NULL function pointer dereference Wolfram Sang
@ 2024-04-26 7:28 ` Sergei Shtylyov
2024-04-26 8:39 ` Wolfram Sang
2024-04-26 8:32 ` Baruch Siach
2024-04-26 9:52 ` Wolfram Sang
2 siblings, 1 reply; 5+ messages in thread
From: Sergei Shtylyov @ 2024-04-26 7:28 UTC (permalink / raw)
To: Wolfram Sang, linux-renesas-soc; +Cc: Baruch Siach, linux-i2c, linux-kernel
On 4/26/24 9:44 AM, Wolfram Sang wrote:
> Brauch reported an OOPS when using the designware controller as target
He's Baruch... :-)
> only. Target-only modes break the assumption of one transfer function
> always being available. Fix this by always checking the pointer in
> __i2c_transfer.
>
> Reported-by: Baruch Siach <baruch@tkos.co.il>
> Closes: https://lore.kernel.org/r/4269631780e5ba789cf1ae391eec1b959def7d99.1712761976.git.baruch@tkos.co.il
> Fixes: 4b1acc43331d ("i2c: core changes for slave support")
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: smbus: fix NULL function pointer dereference
2024-04-26 6:44 [PATCH] i2c: smbus: fix NULL function pointer dereference Wolfram Sang
2024-04-26 7:28 ` Sergei Shtylyov
@ 2024-04-26 8:32 ` Baruch Siach
2024-04-26 9:52 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Baruch Siach @ 2024-04-26 8:32 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-renesas-soc, linux-i2c, linux-kernel
Hi Wolfram,
On Fri, Apr 26 2024, Wolfram Sang wrote:
> Brauch reported an OOPS when using the designware controller as target
> only. Target-only modes break the assumption of one transfer function
> always being available. Fix this by always checking the pointer in
> __i2c_transfer.
>
> Reported-by: Baruch Siach <baruch@tkos.co.il>
> Closes: https://lore.kernel.org/r/4269631780e5ba789cf1ae391eec1b959def7d99.1712761976.git.baruch@tkos.co.il
> Fixes: 4b1acc43331d ("i2c: core changes for slave support")
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Baruch Siach <baruch@tkos.co.il>
Thanks,
baruch
> ---
> drivers/i2c/i2c-core-base.c | 12 ++++++------
> drivers/i2c/i2c-core-smbus.c | 2 +-
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index ff5c486a1dbb..db0d1ac82910 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -2200,13 +2200,18 @@ static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs,
> * Returns negative errno, else the number of messages executed.
> *
> * Adapter lock must be held when calling this function. No debug logging
> - * takes place. adap->algo->master_xfer existence isn't checked.
> + * takes place.
> */
> int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> {
> unsigned long orig_jiffies;
> int ret, try;
>
> + if (!adap->algo->master_xfer) {
> + dev_dbg(&adap->dev, "I2C level transfers not supported\n");
> + return -EOPNOTSUPP;
> + }
> +
> if (WARN_ON(!msgs || num < 1))
> return -EINVAL;
>
> @@ -2273,11 +2278,6 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> {
> int ret;
>
> - if (!adap->algo->master_xfer) {
> - dev_dbg(&adap->dev, "I2C level transfers not supported\n");
> - return -EOPNOTSUPP;
> - }
> -
> /* REVISIT the fault reporting model here is weak:
> *
> * - When we get an error after receiving N bytes from a slave,
> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
> index e3b96fc53b5c..a942c5306a4e 100644
> --- a/drivers/i2c/i2c-core-smbus.c
> +++ b/drivers/i2c/i2c-core-smbus.c
> @@ -596,7 +596,7 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
> break;
> }
>
> - if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
> + if (res != -EOPNOTSUPP)
> goto trace;
> /*
> * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: smbus: fix NULL function pointer dereference
2024-04-26 7:28 ` Sergei Shtylyov
@ 2024-04-26 8:39 ` Wolfram Sang
0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2024-04-26 8:39 UTC (permalink / raw)
To: Sergei Shtylyov; +Cc: linux-renesas-soc, Baruch Siach, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 251 bytes --]
On Fri, Apr 26, 2024 at 10:28:40AM +0300, Sergei Shtylyov wrote:
> On 4/26/24 9:44 AM, Wolfram Sang wrote:
>
> > Brauch reported an OOPS when using the designware controller as target
>
> He's Baruch... :-)
Oh, I am very sorry Baruch!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: smbus: fix NULL function pointer dereference
2024-04-26 6:44 [PATCH] i2c: smbus: fix NULL function pointer dereference Wolfram Sang
2024-04-26 7:28 ` Sergei Shtylyov
2024-04-26 8:32 ` Baruch Siach
@ 2024-04-26 9:52 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2024-04-26 9:52 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Baruch Siach, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 653 bytes --]
On Fri, Apr 26, 2024 at 08:44:08AM +0200, Wolfram Sang wrote:
> Brauch reported an OOPS when using the designware controller as target
> only. Target-only modes break the assumption of one transfer function
> always being available. Fix this by always checking the pointer in
> __i2c_transfer.
>
> Reported-by: Baruch Siach <baruch@tkos.co.il>
> Closes: https://lore.kernel.org/r/4269631780e5ba789cf1ae391eec1b959def7d99.1712761976.git.baruch@tkos.co.il
> Fixes: 4b1acc43331d ("i2c: core changes for slave support")
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Fixed the name typo and applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-26 9:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26 6:44 [PATCH] i2c: smbus: fix NULL function pointer dereference Wolfram Sang
2024-04-26 7:28 ` Sergei Shtylyov
2024-04-26 8:39 ` Wolfram Sang
2024-04-26 8:32 ` Baruch Siach
2024-04-26 9:52 ` Wolfram Sang
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).