Skip to contentSkip to conversation

staging: fbtft: fb_ra8875: prefer usleep_range over udelay

PATCH In review Georgii Druzhinin 3 participants 6 messages Jun 7 – Jun 8

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 staging: fbtft: fb_ra8875: prefer usleep_range over udelay

Replace udelay(100) with usleep_range(100, 120) to avoid busy-waiting and allow the scheduler to utilize the CPU during the delay.

---
 drivers/staging/fbtft/fb_ra8875.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/fbtft/fb_ra8875.c +2 -2
index 0ab1de6647d0..6058934e2ca2 100644
@@ -210,7 +210,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 	}
 	len--;
 
-	udelay(100);
+	usleep_range(100, 120);
 
 	if (len) {
 		buf = (u8 *)par->buf;
@@ -231,7 +231,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 
 	/* restore user spi-speed */
 	par->fbtftops.write = fbtft_write_spi;
-	udelay(100);
+	usleep_range(100, 120);
 }
 
 static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 2/2 staging: fbtft: fbtft-bus: remove prohibited space before close parenthesis

Fix checkpatch.pl error: "space prohibited before that close parenthesis ')'" by removing the empty argument and comma in define_fbtft_write_reg macro calls.

---
 drivers/staging/fbtft/fbtft-bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/fbtft/fbtft-bus.c +2 -2
index 30e436ff19e4..409770891c54 100644
@@ -62,9 +62,9 @@ out:									      \
 }                                                                             \
 EXPORT_SYMBOL(func);
 
-define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, u8, )
+define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, u8)
 define_fbtft_write_reg(fbtft_write_reg16_bus8, __be16, u16, cpu_to_be16)
-define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, u16, )
+define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, u16)
 
 void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...)
 {
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH 2/2] staging: fbtft: fbtft-bus: remove prohibited space before close parenthesis

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Removing the trailing comma from macro invocations results in passing 3 arguments to a 4-argument…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Removing the trailing comma from macro invocations results in passing 3 arguments to a 4-argument macro, breaking the build. --

commit 4aa037560eff822608a285dbbf3f02e9ec0544be
Author: Georgii Druzhinin <[email protected]>

staging: fbtft: fbtft-bus: remove prohibited space before close parenthesis

This commit attempts to resolve a checkpatch.pl formatting warning by removing what appears to be an empty argument and trailing comma from calls to the define_fbtft_write_reg macro.

Quoted 4 lines
drivers/staging/fbtft/fbtft-bus.c +0 -0
index 30e436ff19e4c..409770891c548 100644

[ ... ]

drivers/staging/fbtft/fbtft-bus.c out: \ · line 65

Quoted 6 lines
drivers/staging/fbtft/fbtft-bus.c +1 -1
@@ -62,9 +62,9 @@ out:									      \
 }                                                                             \
 EXPORT_SYMBOL(func);
 
-define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, u8, )
+define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, u8)

[Severity: Low]
Does removing this comma break the build?

The define_fbtft_write_reg macro is defined to take exactly four parameters:
func, buffer_type, data_type, and modifier. By removing the trailing comma, only three arguments are passed to the macro. This will result in a preprocessor error for passing too few arguments.

drivers/staging/fbtft/fbtft-bus.c out: \ · line 67

Quoted 3 lines
drivers/staging/fbtft/fbtft-bus.c +1 -1
 define_fbtft_write_reg(fbtft_write_reg16_bus8, __be16, u16, cpu_to_be16)
-define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, u16, )
+define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, u16)

[Severity: Low]
Will this invocation also fail to compile for the same missing argument reason?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw

Re: [PATCH 2/2] staging: fbtft: fbtft-bus: remove prohibited space before close parenthesis

In reply to Georgii Druzhinin
Quoted 4 lines · Georgii Druzhinin

Fix checkpatch.pl error: "space prohibited before that close parenthesis ')'" by removing the empty argument and comma in define_fbtft_write_reg macro calls.

Please, learn C preprocessor and compile your stuff before submitting. Also since you have a series of the patches it should have had a cover letter.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Georgii Druzhinin
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing restoration of par->fbtftops.write on early error paths in write_reg8_bus8() permanently degrades performance.
- [High] Unaligned 16-bit memory access when writing to the transmit buffer.
--

commit f7268afc18ac218fe8bb9a291f101fccad374b35
Author: Georgii Druzhinin <[email protected]>

staging: fbtft: fb_ra8875: prefer usleep_range over udelay

This commit replaces udelay(100) with usleep_range(100, 120) in write_reg8_bus8() to avoid busy-waiting and allow the scheduler to utilize the CPU during the delay.

drivers/staging/fbtft/fb_ra8875.c static void write_reg8_bus8(struct fbtft_par *par, int len, ...) · line 210

Quoted 6 lines
drivers/staging/fbtft/fb_ra8875.c +0 -0
index 0ab1de6647d07..6058934e2ca2c 100644
@@ -210,7 +210,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 	}

[Severity: High]
This is a pre-existing issue, but returning early in the error paths above this code seems to skip restoring the write function pointer.

If the SPI write fails earlier in write_reg8_bus8(), we return directly:

write_reg8_bus8() {
        ...
        par->fbtftops.write = write_spi;
        ...
        ret = par->fbtftops.write(par, par->buf, 2);
        if (ret < 0) {
                va_end(args);
                dev_err(...);
                return;
        }
        ...
}

Does this leave the device in a permanently degraded state where all subsequent operations use the unoptimized write_spi function instead of restoring fbtft_write_spi at the end of the function?

Quoted 7 lines
drivers/staging/fbtft/fb_ra8875.c +1 -1
 	len--;
 
-	udelay(100);
+	usleep_range(100, 120);
 
 	if (len) {
 		buf = (u8 *)par->buf;

[ ... ]

drivers/staging/fbtft/fb_ra8875.c static void write_reg8_bus8(struct fbtft_par *par, int len, ...) · line 235

Quoted 7 lines
drivers/staging/fbtft/fb_ra8875.c +1 -1
@@ -231,7 +231,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 
 	/* restore user spi-speed */
 	par->fbtftops.write = fbtft_write_spi;
-	udelay(100);
+	usleep_range(100, 120);
 }

While reviewing this file, I also noticed another pre-existing issue in write_vmem16_bus8() that might need attention:

[Severity: High]
This is a pre-existing issue, but does write_vmem16_bus8() cause unaligned memory accesses on the transmit buffer?

The txbuf16 pointer is initialized by adding 1 to a void pointer:

write_vmem16_bus8() {
        ...
        txbuf16 = par->txbuf.buf + 1;
        ...
        for (i = 0; i < to_copy; i++)
                txbuf16[i] = cpu_to_be16(vmem16[i]);
        ...
}

Since par->txbuf.buf is a void pointer, adding 1 increments it by exactly 1 byte, making the address strictly odd.

Will the subsequent 16-bit writes in the loop cause an alignment fault on strict-alignment architectures like older ARM or MIPS often targeted by these display drivers?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#5 lore raw
In reply to Georgii Druzhinin
Quoted 3 lines · Georgii Druzhinin

Replace udelay(100) with usleep_range(100, 120) to avoid busy-waiting and allow the scheduler to utilize the CPU during the delay.

Nice, now go to the lore.kernel.org mailing list archives and check what was done previously on this and why none of the similar patches have been applied so far. Also read README in the driver's folder.

Signature · 2 lines
With Best Regards,
Andy Shevchenko