* [PATCH v8 0/1] Improve usage of 'ret' variable @ 2025-10-22 1:52 Cezar Chiru 2025-10-22 1:52 ` [PATCH v8 1/1] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0 Cezar Chiru 0 siblings, 1 reply; 3+ messages in thread From: Cezar Chiru @ 2025-10-22 1:52 UTC (permalink / raw) To: andi.shyti, wsa+renesas; +Cc: linux-i2c, linux-kernel, Cezar Chiru Hello maintainers, This patch series is a response to Change Requests made by Andi Shyti on [PATCH v7 0/3] i2c: pcf8584: Fix errors and warnings reported by checkpatch and more specific on PATCH: i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0. Change Requests v7->v8: -Move 'ret' variable inside for loop of pcf_xfer() function. -remove initialization of 'ret' variable inside for loop of pcf_xfer() as it is not needed PATCH 1/1: i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0. This patch add spaces around binary operators as reported by checkpatch.pl Move 'ret' variable inside for loop of pcf_xfer() function. Testing: *built kernel and modules with I2C_ALGOPCF=m and my 3 patches applied on top of 6.18.0-rc1. *installed kernel and external modules generated by build on my laptop *rebooted and loaded i2c-algo-pcf.ko without i2c_debug parameter. *when loading the .ko with i2c_debug parameter an error is seen in dmesg and this is expected as the parameter was removed. *No success message related to i2c_algo_pcf was seen in dmesg but also no failures. *Module loading and unloading successful. *No PCF8584 Hardware was available. Cezar Chiru (1): i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0. drivers/i2c/algos/i2c-algo-pcf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 2.43.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v8 1/1] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0. 2025-10-22 1:52 [PATCH v8 0/1] Improve usage of 'ret' variable Cezar Chiru @ 2025-10-22 1:52 ` Cezar Chiru 2025-10-23 6:23 ` Andy Shevchenko 0 siblings, 1 reply; 3+ messages in thread From: Cezar Chiru @ 2025-10-22 1:52 UTC (permalink / raw) To: andi.shyti, wsa+renesas; +Cc: linux-i2c, linux-kernel, Cezar Chiru Require spaces around '=' and '<'. Add spaces around binary operators. Enforce error fixing based on checkpatch.pl output on file. Move 'ret' variable inside for loop. Then check if (ret < 0) break. This improves usage of ret variable. Signed-off-by: Cezar Chiru <chiru.cezar.89@gmail.com> --- drivers/i2c/algos/i2c-algo-pcf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 41a81d37e880..d1b0e55fd871 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c @@ -183,7 +183,7 @@ static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf, struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; int wrcount, status, timeout; - for (wrcount=0; wrcount<count; ++wrcount) { + for (wrcount = 0; wrcount < count; ++wrcount) { i2c_outb(adap, buf[wrcount]); timeout = wait_for_pin(adap, &status); if (timeout) { @@ -272,7 +272,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap, struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; struct i2c_msg *pmsg; int i; - int ret=0, timeout, status; + int timeout, status; if (adap->xfer_begin) adap->xfer_begin(adap->data); @@ -284,9 +284,10 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap, goto out; } - for (i = 0;ret >= 0 && i < num; i++) { - pmsg = &msgs[i]; + for (i = 0; i < num; i++) { + int ret; + pmsg = &msgs[i]; ret = pcf_doAddress(adap, pmsg); /* Send START */ @@ -321,6 +322,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap, ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i + 1 == num)); } + + if (ret < 0) + break; } out: -- 2.43.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v8 1/1] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0. 2025-10-22 1:52 ` [PATCH v8 1/1] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0 Cezar Chiru @ 2025-10-23 6:23 ` Andy Shevchenko 0 siblings, 0 replies; 3+ messages in thread From: Andy Shevchenko @ 2025-10-23 6:23 UTC (permalink / raw) To: Cezar Chiru; +Cc: andi.shyti, wsa+renesas, linux-i2c, linux-kernel On Wed, Oct 22, 2025 at 04:52:13AM +0300, Cezar Chiru wrote: > Require spaces around '=' and '<'. Add spaces around binary operators. > Enforce error fixing based on checkpatch.pl output on file. > Move 'ret' variable inside for loop. Then check if (ret < 0) break. This > improves usage of ret variable. No need to have a cover letter for a single patch. > Signed-off-by: Cezar Chiru <chiru.cezar.89@gmail.com> > --- You may use this comment block space for changelog and additional comments if required. ... > goto out; > } > > - for (i = 0;ret >= 0 && i < num; i++) { > - pmsg = &msgs[i]; > + for (i = 0; i < num; i++) { > + int ret; > > + pmsg = &msgs[i]; > ret = pcf_doAddress(adap, pmsg); > > /* Send START */ > ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len, > (i + 1 == num)); > } > + > + if (ret < 0) > + break; I think goto out; is better as it's kept consistent with other error path branches above. > } > > out: -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-23 6:23 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-10-22 1:52 [PATCH v8 0/1] Improve usage of 'ret' variable Cezar Chiru 2025-10-22 1:52 ` [PATCH v8 1/1] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0 Cezar Chiru 2025-10-23 6:23 ` Andy Shevchenko
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®