[v3,5/9] auxdisplay: ht16k33: Define a few helper macros

Message ID 20240219170337.2161754-6-andriy.shevchenko@linux.intel.com
State New
Headers
Series auxdisplay: linedisp: Clean up and add new driver |

Commit Message

Andy Shevchenko Feb. 19, 2024, 4:58 p.m. UTC
  Define a few helper macros — wrappers on contaoner_of)() — for easier
maintenance in the future. While at it, include missing container_of.h.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/auxdisplay/ht16k33.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
  

Comments

Andy Shevchenko Feb. 20, 2024, 6:05 p.m. UTC | #1
On Mon, Feb 19, 2024 at 06:58:04PM +0200, Andy Shevchenko wrote:
> Define a few helper macros — wrappers on contaoner_of)() — for easier

I have fixed 'container_of()' above locally.

> maintenance in the future. While at it, include missing container_of.h.
  
Geert Uytterhoeven Feb. 26, 2024, 3:40 p.m. UTC | #2
On Tue, Feb 20, 2024 at 7:05 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Mon, Feb 19, 2024 at 06:58:04PM +0200, Andy Shevchenko wrote:
> > Define a few helper macros — wrappers on contaoner_of)() — for easier
>
> I have fixed 'container_of()' above locally.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert
  

Patch

diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index f016130835b1..b76c4d83528f 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -15,6 +15,7 @@ 
 #include <linux/property.h>
 #include <linux/fb.h>
 #include <linux/backlight.h>
+#include <linux/container_of.h>
 #include <linux/input.h>
 #include <linux/input/matrix_keypad.h>
 #include <linux/leds.h>
@@ -107,6 +108,15 @@  struct ht16k33_priv {
 	uint8_t blink;
 };
 
+#define ht16k33_work_to_priv(p)				\
+	container_of(p, struct ht16k33_priv, work.work)
+
+#define ht16k33_led_to_priv(p)				\
+	container_of(p, struct ht16k33_priv, led)
+
+#define ht16k33_linedisp_to_priv(p)			\
+	container_of(p, struct ht16k33_priv, seg.linedisp)
+
 static const struct fb_fix_screeninfo ht16k33_fb_fix = {
 	.id		= DRIVER_NAME,
 	.type		= FB_TYPE_PACKED_PIXELS,
@@ -194,8 +204,7 @@  static int ht16k33_brightness_set(struct ht16k33_priv *priv,
 static int ht16k33_brightness_set_blocking(struct led_classdev *led_cdev,
 					   enum led_brightness brightness)
 {
-	struct ht16k33_priv *priv = container_of(led_cdev, struct ht16k33_priv,
-						 led);
+	struct ht16k33_priv *priv = ht16k33_led_to_priv(led_cdev);
 
 	return ht16k33_brightness_set(priv, brightness);
 }
@@ -203,8 +212,7 @@  static int ht16k33_brightness_set_blocking(struct led_classdev *led_cdev,
 static int ht16k33_blink_set(struct led_classdev *led_cdev,
 			     unsigned long *delay_on, unsigned long *delay_off)
 {
-	struct ht16k33_priv *priv = container_of(led_cdev, struct ht16k33_priv,
-						 led);
+	struct ht16k33_priv *priv = ht16k33_led_to_priv(led_cdev);
 	unsigned int delay;
 	uint8_t blink;
 	int err;
@@ -246,8 +254,7 @@  static void ht16k33_fb_queue(struct ht16k33_priv *priv)
  */
 static void ht16k33_fb_update(struct work_struct *work)
 {
-	struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
-						 work.work);
+	struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
 	uint8_t *p1, *p2;
@@ -441,8 +448,7 @@  static void ht16k33_keypad_stop(struct input_dev *dev)
 
 static void ht16k33_seg7_update(struct work_struct *work)
 {
-	struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
-						 work.work);
+	struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
 	struct ht16k33_seg *seg = &priv->seg;
 	char *s = seg->linedisp.buf;
 	uint8_t buf[9];
@@ -462,8 +468,7 @@  static void ht16k33_seg7_update(struct work_struct *work)
 
 static void ht16k33_seg14_update(struct work_struct *work)
 {
-	struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
-						 work.work);
+	struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
 	struct ht16k33_seg *seg = &priv->seg;
 	char *s = seg->linedisp.buf;
 	uint8_t buf[8];
@@ -478,8 +483,7 @@  static void ht16k33_seg14_update(struct work_struct *work)
 
 static void ht16k33_linedisp_update(struct linedisp *linedisp)
 {
-	struct ht16k33_priv *priv = container_of(linedisp, struct ht16k33_priv,
-						 seg.linedisp);
+	struct ht16k33_priv *priv = ht16k33_linedisp_to_priv(linedisp);
 
 	schedule_delayed_work(&priv->work, 0);
 }