* [PATCH] staging: fbtft: use guard() to simplify code
@ 2026-01-28 21:26 Paul Retourné
2026-01-28 22:08 ` Andy Shevchenko
2026-01-29 4:38 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Paul Retourné @ 2026-01-28 21:26 UTC (permalink / raw)
To: andy, gregkh
Cc: Paul Retourné, dri-devel, linux-fbdev, linux-staging,
linux-kernel
Use guard() to simplify mutex locking. No functional change.
Signed-off-by: Paul Retourné <paul.retourne@orange.fr>
---
drivers/staging/fbtft/fb_ssd1305.c | 4 ++--
drivers/staging/fbtft/fb_ssd1306.c | 4 ++--
drivers/staging/fbtft/fbtft-sysfs.c | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/fbtft/fb_ssd1305.c b/drivers/staging/fbtft/fb_ssd1305.c
index 020fe48fed0be..d9215cb35e8f8 100644
--- a/drivers/staging/fbtft/fb_ssd1305.c
+++ b/drivers/staging/fbtft/fb_ssd1305.c
@@ -10,6 +10,7 @@
#include <linux/init.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
+#include <linux/cleanup.h>
#include "fbtft.h"
@@ -35,12 +36,11 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
if (par->gamma.curves[0] == 0) {
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
if (par->info->var.yres == 64)
par->gamma.curves[0] = 0xCF;
else
par->gamma.curves[0] = 0x8F;
- mutex_unlock(&par->gamma.lock);
}
/* Set Display OFF */
diff --git a/drivers/staging/fbtft/fb_ssd1306.c b/drivers/staging/fbtft/fb_ssd1306.c
index 478d710469b91..c230d599ff928 100644
--- a/drivers/staging/fbtft/fb_ssd1306.c
+++ b/drivers/staging/fbtft/fb_ssd1306.c
@@ -10,6 +10,7 @@
#include <linux/init.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
+#include <linux/cleanup.h>
#include "fbtft.h"
@@ -34,12 +35,11 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
if (par->gamma.curves[0] == 0) {
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
if (par->info->var.yres == 64)
par->gamma.curves[0] = 0xCF;
else
par->gamma.curves[0] = 0x8F;
- mutex_unlock(&par->gamma.lock);
}
/* Set Display OFF */
diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
index e45c90a03a903..72d6cf899336e 100644
--- a/drivers/staging/fbtft/fbtft-sysfs.c
+++ b/drivers/staging/fbtft/fbtft-sysfs.c
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/cleanup.h>
+
#include "fbtft.h"
#include "internal.h"
@@ -95,14 +97,13 @@ sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf)
ssize_t len = 0;
unsigned int i, j;
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
for (i = 0; i < par->gamma.num_curves; i++) {
for (j = 0; j < par->gamma.num_values; j++)
len += scnprintf(&buf[len], PAGE_SIZE,
"%04x ", curves[i * par->gamma.num_values + j]);
buf[len - 1] = '\n';
}
- mutex_unlock(&par->gamma.lock);
return len;
}
@@ -124,11 +125,10 @@ static ssize_t store_gamma_curve(struct device *device,
if (ret)
return ret;
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
memcpy(par->gamma.curves, tmp_curves,
par->gamma.num_curves * par->gamma.num_values *
sizeof(tmp_curves[0]));
- mutex_unlock(&par->gamma.lock);
return count;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] staging: fbtft: use guard() to simplify code
2026-01-28 21:26 [PATCH] staging: fbtft: use guard() to simplify code Paul Retourné
@ 2026-01-28 22:08 ` Andy Shevchenko
2026-01-29 9:18 ` Paul Retourne
2026-01-29 4:38 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-01-28 22:08 UTC (permalink / raw)
To: Paul Retourné
Cc: andy, gregkh, dri-devel, linux-fbdev, linux-staging, linux-kernel
On Wed, Jan 28, 2026 at 10:26:42PM +0100, Paul Retourné wrote:
> Use guard() to simplify mutex locking. No functional change.
...
> #include <linux/init.h>
> #include <linux/gpio/consumer.h>
> #include <linux/delay.h>
> +#include <linux/cleanup.h>
Try to squeeze the new inclusion into the longest ordered chain with some
pieces left unordered. With the given context the lease is to put it before
delay.h, but maybe there is a better place.
...
> if (par->gamma.curves[0] == 0) {
> - mutex_lock(&par->gamma.lock);
> + guard(mutex)(&par->gamma.lock);
> if (par->info->var.yres == 64)
> par->gamma.curves[0] = 0xCF;
> else
> par->gamma.curves[0] = 0x8F;
> - mutex_unlock(&par->gamma.lock);
> }
This has close to 0 added value. Don't do conversion just for fun.
...
> --- a/drivers/staging/fbtft/fb_ssd1306.c
> +++ b/drivers/staging/fbtft/fb_ssd1306.c
Ditto.
...
Sorry, but I don't see much value in this change.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] staging: fbtft: use guard() to simplify code
2026-01-28 22:08 ` Andy Shevchenko
@ 2026-01-29 9:18 ` Paul Retourne
0 siblings, 0 replies; 4+ messages in thread
From: Paul Retourne @ 2026-01-29 9:18 UTC (permalink / raw)
To: Andy Shevchenko
Cc: andy, gregkh, dri-devel, linux-fbdev, linux-staging, linux-kernel,
Paul Retourne
On 1/28/26 23:08, Andy Shevchenko wrote:
> Sorry, but I don't see much value in this change.
Understood, I see the problem, I'll try to do changes that are actually
useful in the future.
Thank you for looking at it and taking the time to answer.
--
Paul Retourné
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: fbtft: use guard() to simplify code
2026-01-28 21:26 [PATCH] staging: fbtft: use guard() to simplify code Paul Retourné
2026-01-28 22:08 ` Andy Shevchenko
@ 2026-01-29 4:38 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-01-29 4:38 UTC (permalink / raw)
To: Paul Retourné
Cc: andy, dri-devel, linux-fbdev, linux-staging, linux-kernel
On Wed, Jan 28, 2026 at 10:26:42PM +0100, Paul Retourné wrote:
> Use guard() to simplify mutex locking. No functional change.
It's best to use guard() for new code, not touching existing code as:
> 3 files changed, 8 insertions(+), 8 deletions(-)
This made no change overall at all :(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-29 9:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 21:26 [PATCH] staging: fbtft: use guard() to simplify code Paul Retourné
2026-01-28 22:08 ` Andy Shevchenko
2026-01-29 9:18 ` Paul Retourne
2026-01-29 4:38 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox