Skip to contentSkip to conversation

spi: Remove unneeded parentheses in spi_map_buf()

PATCH In review Andy Shevchenko 3 participants 4 messages Jun 19, 2021 – Jun 21, 2021 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: Remove unneeded parentheses in spi_map_buf()

The boolean expression to get kmap_buf is hard to read due to too many unneeded parentheses. Remove them for good.

---
 drivers/spi/spi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/spi/spi.c +2 -3
index 16b377581d16..0e4917a55eaa 100644
@@ -873,9 +873,8 @@ int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
 	const bool vmalloced_buf = is_vmalloc_addr(buf);
 	unsigned int max_seg_size = dma_get_max_seg_size(dev);
 #ifdef CONFIG_HIGHMEM
-	const bool kmap_buf = ((unsigned long)buf >= PKMAP_BASE &&
-				(unsigned long)buf < (PKMAP_BASE +
-					(LAST_PKMAP * PAGE_SIZE)));
+	const bool kmap_buf = (unsigned long)buf >= PKMAP_BASE &&
+			      (unsigned long)buf < (PKMAP_BASE + LAST_PKMAP * PAGE_SIZE);
 #else
 	const bool kmap_buf = false;
 #endif
Signature · 1 line
2.30.2
maintainer
#1 lore raw

drivers/spi/spi.c int spi_map_buf(struct spi_controller *ctlr, struct device *dev, · line 877

Quoted 8 lines · Andy Shevchenko

The boolean expression to get kmap_buf is hard to read due to too many unneeded parentheses. Remove them for good.

drivers/spi/spi.c +2 -3
-	const bool kmap_buf = ((unsigned long)buf >= PKMAP_BASE &&
-				(unsigned long)buf < (PKMAP_BASE +
-					(LAST_PKMAP * PAGE_SIZE)));
+	const bool kmap_buf = (unsigned long)buf >= PKMAP_BASE &&
+			      (unsigned long)buf < (PKMAP_BASE + LAST_PKMAP * PAGE_SIZE);

No, I think this makes things worse - to the extent there's an issue here it's not excessive brackets.

#2 lore raw
Quoted 5 lines · Mark Brown
Quoted 2 lines · Andy Shevchenko

The boolean expression to get kmap_buf is hard to read due to too many unneeded parentheses. Remove them for good.

Quoted 8 lines

drivers/spi/spi.c int spi_map_buf(struct spi_controller *ctlr, struct device *dev, · line 877

Quoted 5 lines
drivers/spi/spi.c +2 -3
-     const bool kmap_buf = ((unsigned long)buf >= PKMAP_BASE &&
-                             (unsigned long)buf < (PKMAP_BASE +
-                                     (LAST_PKMAP * PAGE_SIZE)));
+     const bool kmap_buf = (unsigned long)buf >= PKMAP_BASE &&
+                           (unsigned long)buf < (PKMAP_BASE + LAST_PKMAP * PAGE_SIZE);

No, I think this makes things worse - to the extent there's an issue here it's not excessive brackets.

How? I can't see any issues here and dropping excessive brackets helps to read it better. For example, the exterior brackets do nothing except making it harder to read, i.e. the expression inside them is already type of boolean and I have no clue what they are for.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Mark Brown
Quoted 8 lines · Andy Shevchenko

The boolean expression to get kmap_buf is hard to read due to too many unneeded parentheses. Remove them for good.

drivers/spi/spi.c +2 -3
-     const bool kmap_buf = ((unsigned long)buf >= PKMAP_BASE &&
-                             (unsigned long)buf < (PKMAP_BASE +
-                                     (LAST_PKMAP * PAGE_SIZE)));
+     const bool kmap_buf = (unsigned long)buf >= PKMAP_BASE &&
+                           (unsigned long)buf < (PKMAP_BASE + LAST_PKMAP * PAGE_SIZE);
Quoted 7 lines
Quoted 2 lines

No, I think this makes things worse - to the extent there's an issue here it's not excessive brackets.

How? I can't see any issues here and dropping excessive brackets helps to read it better. For example, the exterior brackets do nothing except making it harder to read, i.e. the expression inside them is already type of boolean and I have no clue what they are for.

This is purely a taste thing. I think the >= and && being the same length and the second condition being visually distinct from the first don't help here.