Skip to contentSkip to conversation

drm/ofdrm: Fix sparse warnings

PATCH Superseded Thomas Zimmermann 2 participants 6 messages Oct 28, 2022 – Nov 2, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover drm/ofdrm: Fix sparse warnings

Fix two types of sparse warnings in ofdrm. Reported by the LKP bot.

v2:
* convert PCI ID endianness (Alex)

Thomas Zimmermann (2):
drm/ofdrm: Convert PCI IDs to CPU endianness for comparing drm/ofdrm: Cast error pointers to void __iomem *

 drivers/gpu/drm/tiny/ofdrm.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

base-commit: 746559738f1335241ea686566cb654847c20d7a4

Signature · 1 line
2.38.0
author maintainer
#1 lore raw

PATCH v2 1/2 drm/ofdrm: Convert PCI IDs to CPU endianness for comparing

Properties of 32-bit integers are returned from the OF device tree as type __be32. Convert PCI vendor and device IDs from __be32 to host endianness before comparing them to constants. All relevant machines are old, big-endian Macintosh systems; hence the bug never happened in practice.

Fixes sparse warnings shown below.

drivers/gpu/drm/tiny/ofdrm.c:237:17: warning: restricted __be32 degrades to integer drivers/gpu/drm/tiny/ofdrm.c:238:18: warning: restricted __be32 degrades to integer drivers/gpu/drm/tiny/ofdrm.c:238:54: warning: restricted __be32 degrades to integer

See [1] for the bug report.

v2:
* convert endianness (Alex)

---
 drivers/gpu/drm/tiny/ofdrm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/tiny/ofdrm.c +8 -3
index 0e1cc2369afcc..44f13a2b372be 100644
@@ -231,7 +231,7 @@ static u64 display_get_address_of(struct drm_device *dev, struct device_node *of
 	return address;
 }
 
-static bool is_avivo(__be32 vendor, __be32 device)
+static bool is_avivo(u32 vendor, u32 device)
 {
 	/* This will match most R5xx */
 	return (vendor == PCI_VENDOR_ID_ATI) &&
@@ -265,8 +265,13 @@ static enum ofdrm_model display_get_model_of(struct drm_device *dev, struct devi
 		of_parent = of_get_parent(of_node);
 		vendor_p = of_get_property(of_parent, "vendor-id", NULL);
 		device_p = of_get_property(of_parent, "device-id", NULL);
-		if (vendor_p && device_p && is_avivo(*vendor_p, *device_p))
-			model = OFDRM_MODEL_AVIVO;
+		if (vendor_p && device_p) {
+			u32 vendor = be32_to_cpup(vendor_p);
+			u32 device = be32_to_cpup(device_p);
+
+			if (is_avivo(vendor, device))
+				model = OFDRM_MODEL_AVIVO;
+		}
 		of_node_put(of_parent);
 	} else if (of_device_is_compatible(of_node, "qemu,std-vga")) {
 		model = OFDRM_MODEL_QEMU;
Signature · 1 line
2.38.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] drm/ofdrm: Convert PCI IDs to CPU endianness for comparing

Quoted 14 lines · Thomas Zimmermann

Properties of 32-bit integers are returned from the OF device tree as type __be32. Convert PCI vendor and device IDs from __be32 to host endianness before comparing them to constants. All relevant machines are old, big-endian Macintosh systems; hence the bug never happened in practice.

Fixes sparse warnings shown below.

drivers/gpu/drm/tiny/ofdrm.c:237:17: warning: restricted __be32 degrades to integer drivers/gpu/drm/tiny/ofdrm.c:238:18: warning: restricted __be32 degrades to integer drivers/gpu/drm/tiny/ofdrm.c:238:54: warning: restricted __be32 degrades to integer

See [1] for the bug report.

Quoted 7 lines

v2:
* convert endianness (Alex)

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#3 lore raw

PATCH v2 2/2 drm/ofdrm: Cast error pointers to void __iomem *

In reply to Thomas Zimmermann

Cast error pointers when returning them as void __iomem *. Fixes a number of Sparse warnings, such as the ones shown below.

../drivers/gpu/drm/tiny/ofdrm.c:439:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:439:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:439:31: got void *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:442:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: got void *

See [1] for the bug report.

---
 drivers/gpu/drm/tiny/ofdrm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/tiny/ofdrm.c +8 -8
index 44f13a2b372be..f1c301820d54b 100644
@@ -438,21 +438,21 @@ static void __iomem *get_cmap_address_of(struct ofdrm_device *odev, struct devic
 	if (!addr_p)
 		addr_p = of_get_address(of_node, bar_no, &max_size, &flags);
 	if (!addr_p)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 
 	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 
 	if ((offset + size) >= max_size)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 
 	address = of_translate_address(of_node, addr_p);
 	if (address == OF_BAD_ADDR)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 
 	mem = devm_ioremap(dev->dev, address + offset, size);
 	if (!mem)
-		return ERR_PTR(-ENOMEM);
+		return (void __iomem *)ERR_PTR(-ENOMEM);
 
 	return mem;
 }
@@ -470,7 +470,7 @@ static void __iomem *ofdrm_mach64_cmap_ioremap(struct ofdrm_device *odev,
 
 	cmap_base = devm_ioremap(dev->dev, address, 0x1000);
 	if (!cmap_base)
-		return ERR_PTR(-ENOMEM);
+		return (void __iomem *)ERR_PTR(-ENOMEM);
 
 	return cmap_base;
 }
@@ -629,11 +629,11 @@ static void __iomem *ofdrm_qemu_cmap_ioremap(struct ofdrm_device *odev,
 
 	address = of_translate_address(of_node, io_of_addr);
 	if (address == OF_BAD_ADDR)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 
 	cmap_base = devm_ioremap(dev->dev, address + 0x3c8, 2);
 	if (!cmap_base)
-		return ERR_PTR(-ENOMEM);
+		return (void __iomem *)ERR_PTR(-ENOMEM);
 
 	return cmap_base;
 }
Signature · 1 line
2.38.0
#4 lore raw

Re: [PATCH v2 2/2] drm/ofdrm: Cast error pointers to void __iomem *

Hello Thomas,

Quoted 24 lines · Thomas Zimmermann

Cast error pointers when returning them as void __iomem *. Fixes a number of Sparse warnings, such as the ones shown below.

../drivers/gpu/drm/tiny/ofdrm.c:439:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:439:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:439:31: got void *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:442:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: got void *

See [1] for the bug report.

---
 drivers/gpu/drm/tiny/ofdrm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/tiny/ofdrm.c +0 -0
index 44f13a2b372be..f1c301820d54b 100644

drivers/gpu/drm/tiny/ofdrm.c static void __iomem *get_cmap_address_of(struct ofdrm_device *odev, struct devic · line 442

Quoted 6 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -1
@@ -438,21 +438,21 @@ static void __iomem *get_cmap_address_of(struct ofdrm_device *odev, struct devic
 	if (!addr_p)
 		addr_p = of_get_address(of_node, bar_no, &max_size, &flags);
 	if (!addr_p)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 

There's an IOMEM_ERR_PTR() macro already for these cases. If you use that instead, feel free to add my r-b when posting v3.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#5 lore raw

Re: [PATCH v2 2/2] drm/ofdrm: Cast error pointers to void __iomem *

Hi

Am 02.11.22 um 14:36 schrieb Javier Martinez Canillas:

Quoted 22 lines

Hello Thomas,

Quoted 19 lines · Thomas Zimmermann

Cast error pointers when returning them as void __iomem *. Fixes a number of Sparse warnings, such as the ones shown below.

../drivers/gpu/drm/tiny/ofdrm.c:439:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:439:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:439:31: got void *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: warning: incorrect type in return expression (different address spaces)
../drivers/gpu/drm/tiny/ofdrm.c:442:31: expected void [noderef] __iomem *
../drivers/gpu/drm/tiny/ofdrm.c:442:31: got void *

See [1] for the bug report.

---
  drivers/gpu/drm/tiny/ofdrm.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
Quoted 14 lines

drivers/gpu/drm/tiny/ofdrm.c static void __iomem *get_cmap_address_of(struct ofdrm_device *odev, struct devic · line 442

Quoted 11 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -1
index 44f13a2b372be..f1c301820d54b 100644
@@ -438,21 +438,21 @@ static void __iomem *get_cmap_address_of(struct ofdrm_device *odev, struct devic
  	if (!addr_p)
  		addr_p = of_get_address(of_node, bar_no, &max_size, &flags);
  	if (!addr_p)
-		return ERR_PTR(-ENODEV);
+		return (void __iomem *)ERR_PTR(-ENODEV);
 

There's an IOMEM_ERR_PTR() macro already for these cases. If you use that instead, feel free to add my r-b when posting v3.

Thanks a lot. I was looking for such a macro and couldn't find it. So it's in io.h.

Best regards
Thomas

Quoted 1 line
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev