Skip to contentSkip to conversation

tty: atmel_serial: Use of_property_present() for non-boolean properties

PATCH In review Rob Herring (Arm) 3 participants 3 messages Jan 9, 2025 – Jan 10, 2025

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

PATCH 1/1 tty: atmel_serial: Use of_property_present() for non-boolean properties

The use of of_property_read_bool() for non-boolean properties is deprecated in favor of of_property_present() when testing for property presence.

As of_property_present() returns a boolean, use that directly and simplify the code a bit while we're here.

---
 drivers/tty/serial/atmel_serial.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/tty/serial/atmel_serial.c +4 -14
index 0cf05ac18993..f44f9d20a974 100644
@@ -1727,26 +1727,16 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
 
 	/* DMA/PDC usage specification */
 	if (of_property_read_bool(np, "atmel,use-dma-rx")) {
-		if (of_property_read_bool(np, "dmas")) {
-			atmel_port->use_dma_rx  = true;
-			atmel_port->use_pdc_rx  = false;
-		} else {
-			atmel_port->use_dma_rx  = false;
-			atmel_port->use_pdc_rx  = true;
-		}
+		atmel_port->use_dma_rx = of_property_present(np, "dmas");
+		atmel_port->use_pdc_rx = !atmel_port->use_dma_rx;
 	} else {
 		atmel_port->use_dma_rx  = false;
 		atmel_port->use_pdc_rx  = false;
 	}
 
 	if (of_property_read_bool(np, "atmel,use-dma-tx")) {
-		if (of_property_read_bool(np, "dmas")) {
-			atmel_port->use_dma_tx  = true;
-			atmel_port->use_pdc_tx  = false;
-		} else {
-			atmel_port->use_dma_tx  = false;
-			atmel_port->use_pdc_tx  = true;
-		}
+		atmel_port->use_dma_tx = of_property_present(np, "dmas");
+		atmel_port->use_pdc_tx = !atmel_port->use_dma_tx;
 	} else {
 		atmel_port->use_dma_tx  = false;
 		atmel_port->use_pdc_tx  = false;
Signature · 1 line
2.45.2
maintainer Acked-by on v1 1/1
#1 lore raw

Le 09/01/2025 à 19:20, Rob Herring (Arm) a écrit :

Quoted 37 lines

The use of of_property_read_bool() for non-boolean properties is deprecated in favor of of_property_present() when testing for property presence.

As of_property_present() returns a boolean, use that directly and simplify the code a bit while we're here.

---
  drivers/tty/serial/atmel_serial.c | 18 ++++--------------
  1 file changed, 4 insertions(+), 14 deletions(-)
drivers/tty/serial/atmel_serial.c +2 -9
index 0cf05ac18993..f44f9d20a974 100644
@@ -1727,26 +1727,16 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
 
  	/* DMA/PDC usage specification */
  	if (of_property_read_bool(np, "atmel,use-dma-rx")) {
-		if (of_property_read_bool(np, "dmas")) {
-			atmel_port->use_dma_rx  = true;
-			atmel_port->use_pdc_rx  = false;
-		} else {
-			atmel_port->use_dma_rx  = false;
-			atmel_port->use_pdc_rx  = true;
-		}
+		atmel_port->use_dma_rx = of_property_present(np, "dmas");
+		atmel_port->use_pdc_rx = !atmel_port->use_dma_rx;
  	} else {
  		atmel_port->use_dma_rx  = false;
  		atmel_port->use_pdc_rx  = false;
  	}
 
  	if (of_property_read_bool(np, "atmel,use-dma-tx")) {
-		if (of_property_read_bool(np, "dmas")) {
-			atmel_port->use_dma_tx  = true;

drivers/tty/serial/atmel_serial.c static void atmel_init_property(struct atmel_uart_port *atmel_port, · line 1742

Quoted 10 lines
drivers/tty/serial/atmel_serial.c +2 -5
-			atmel_port->use_pdc_tx  = false;
-		} else {
-			atmel_port->use_dma_tx  = false;
-			atmel_port->use_pdc_tx  = true;
-		}
+		atmel_port->use_dma_tx = of_property_present(np, "dmas");
+		atmel_port->use_pdc_tx = !atmel_port->use_dma_tx;
  	} else {
  		atmel_port->use_dma_tx  = false;
  		atmel_port->use_pdc_tx  = false;

The code is indeed nicer like that!
Thanks!

Regards,
Richard

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Rob Herring (Arm)
Quoted 8 lines · Rob Herring (Arm)

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

The use of of_property_read_bool() for non-boolean properties is deprecated in favor of of_property_present() when testing for property presence.

As of_property_present() returns a boolean, use that directly and simplify the code a bit while we're here.

Indeed! Thanks Rob.

Quoted 43 lines
---
  drivers/tty/serial/atmel_serial.c | 18 ++++--------------
  1 file changed, 4 insertions(+), 14 deletions(-)
drivers/tty/serial/atmel_serial.c +4 -15
index 0cf05ac18993..f44f9d20a974 100644
@@ -1727,26 +1727,16 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
 
         /* DMA/PDC usage specification */
         if (of_property_read_bool(np, "atmel,use-dma-rx")) {
-               if (of_property_read_bool(np, "dmas")) {
-                       atmel_port->use_dma_rx  = true;
-                       atmel_port->use_pdc_rx  = false;
-               } else {
-                       atmel_port->use_dma_rx  = false;
-                       atmel_port->use_pdc_rx  = true;
-               }
+               atmel_port->use_dma_rx = of_property_present(np, "dmas");
+               atmel_port->use_pdc_rx = !atmel_port->use_dma_rx;
         } else {
                 atmel_port->use_dma_rx  = false;
                 atmel_port->use_pdc_rx  = false;
         }
 
         if (of_property_read_bool(np, "atmel,use-dma-tx")) {
-               if (of_property_read_bool(np, "dmas")) {
-                       atmel_port->use_dma_tx  = true;
-                       atmel_port->use_pdc_tx  = false;
-               } else {
-                       atmel_port->use_dma_tx  = false;
-                       atmel_port->use_pdc_tx  = true;
-               }
+               atmel_port->use_dma_tx = of_property_present(np, "dmas");
+               atmel_port->use_pdc_tx = !atmel_port->use_dma_tx;
         } else {
                 atmel_port->use_dma_tx  = false;
                 atmel_port->use_pdc_tx  = false;
--

2.45.2