Skip to contentSkip to conversation

drm/ofdrm: Fix sparse warnings

PATCH Superseded Thomas Zimmermann 2 participants 7 messages Oct 27, 2022 – Oct 28, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ofdrm: Fix sparse warnings

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

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

 drivers/gpu/drm/tiny/ofdrm.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

base-commit: 746559738f1335241ea686566cb654847c20d7a4

Signature · 1 line
2.38.0
author maintainer
#1 lore raw

PATCH 1/2 drm/ofdrm: Cast PCI IDs to u32 for comparing

Properties of 32-bit integers are returned from the OF device tree as type __be32. Cast PCI vendor and device IDs from __be32 to u32 before comparing them to constants. 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.

---
 drivers/gpu/drm/tiny/ofdrm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/tiny/ofdrm.c +4 -1
index 0e1cc2369afcc..0da8b248ccc6e 100644
@@ -231,8 +231,11 @@ 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(__be32 vendor_id, __be32 device_id)
 {
+	u32 vendor = (__force u32)vendor_id;
+	u32 device = (__force u32)device_id;
+
 	/* This will match most R5xx */
 	return (vendor == PCI_VENDOR_ID_ATI) &&
 	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
Signature · 1 line
2.38.0
#2 lore raw

Re: [PATCH 1/2] drm/ofdrm: Cast PCI IDs to u32 for comparing

Hello Thomas,

Am Donnerstag, 27. Oktober 2022, 13:57:06 CEST schrieb Thomas Zimmermann:

Quoted 23 lines

Properties of 32-bit integers are returned from the OF device tree as type __be32. Cast PCI vendor and device IDs from __be32 to u32 before comparing them to constants. 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.

# [1] ---

 drivers/gpu/drm/tiny/ofdrm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/tiny/ofdrm.c +0 -0
index 0e1cc2369afcc..0da8b248ccc6e 100644

drivers/gpu/drm/tiny/ofdrm.c static u64 display_get_address_of(struct drm_device · line 237

Quoted 8 lines
drivers/gpu/drm/tiny/ofdrm.c +3 -1
@@ -231,8 +231,11 @@ 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(__be32 vendor_id, __be32 device_id)
 {
+	u32 vendor = (__force u32)vendor_id;
+	u32 device = (__force u32)device_id;

I don't have much context, but just from reading this, shouldn't this be be32_to_cpu() instead?

Best regards,
Alexander

Quoted 4 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -0
+
 	/* This will match most R5xx */
 	return (vendor == PCI_VENDOR_ID_ATI) &&
 	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
author maintainer
#3 lore raw

Re: [PATCH 1/2] drm/ofdrm: Cast PCI IDs to u32 for comparing

Hi

Am 27.10.22 um 15:07 schrieb Alexander Stein:

Quoted 29 lines

Hello Thomas,

Am Donnerstag, 27. Oktober 2022, 13:57:06 CEST schrieb Thomas Zimmermann:

Quoted 26 lines

Properties of 32-bit integers are returned from the OF device tree as type __be32. Cast PCI vendor and device IDs from __be32 to u32 before comparing them to constants. 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.

# [1] ---

  drivers/gpu/drm/tiny/ofdrm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/tiny/ofdrm.c +0 -0
index 0e1cc2369afcc..0da8b248ccc6e 100644
@@ -231,8 +231,11 @@ static u64 display_get_address_of(struct drm_device
 *dev, struct device_node *of return address;
  }
 
Quoted 8 lines

drivers/gpu/drm/tiny/ofdrm.c static u64 display_get_address_of(struct drm_device *dev, struct device_node *of · line 237

Quoted 5 lines
drivers/gpu/drm/tiny/ofdrm.c +3 -1
-static bool is_avivo(__be32 vendor, __be32 device)
+static bool is_avivo(__be32 vendor_id, __be32 device_id)
  {
+	u32 vendor = (__force u32)vendor_id;
+	u32 device = (__force u32)device_id;

I don't have much context, but just from reading this, shouldn't this be be32_to_cpu() instead?

I should have explained that in the commit message. The values are supposed to be in big endian. We compare to PCI ids. The code originally was taken from [1], which does the right thing. The next version will add this info to the commit message.

Best regards
Thomas

[1] https://elixir.bootlin.com/linux/v6.0.5/source/drivers/video/fbdev/offb.c#L357

Quoted 12 lines

Best regards,
Alexander

Quoted 4 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -0
+
  	/* This will match most R5xx */
  	return (vendor == PCI_VENDOR_ID_ATI) &&
  	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
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
#4 lore raw

Re: [PATCH 1/2] drm/ofdrm: Cast PCI IDs to u32 for comparing

Hi Thomas,

Am Donnerstag, 27. Oktober 2022, 16:04:34 CEST schrieb Thomas Zimmermann:

Quoted 56 lines

* PGP Signed: 10/27/2022 at 04:04:34 PM

Hi

Am 27.10.22 um 15:07 schrieb Alexander Stein:

Quoted 38 lines

Hello Thomas,

Am Donnerstag, 27. Oktober 2022, 13:57:06 CEST schrieb Thomas Zimmermann:

Quoted 35 lines

Properties of 32-bit integers are returned from the OF device tree as type __be32. Cast PCI vendor and device IDs from __be32 to u32 before comparing them to constants. 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.

Link:
https://lore.kernel.org/dri-devel/[email protected]/ #
[1] ---

  drivers/gpu/drm/tiny/ofdrm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/tiny/ofdrm.c +1 -1
index 0e1cc2369afcc..0da8b248ccc6e 100644
@@ -231,8 +231,11 @@ 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(__be32 vendor_id, __be32 device_id)
 
Quoted 7 lines

drivers/gpu/drm/tiny/ofdrm.c static u64 display_get_address_of(struct drm_device *dev, struct device_node *of · line 237

Quoted 4 lines
drivers/gpu/drm/tiny/ofdrm.c +2 -0
  {
 
+	u32 vendor = (__force u32)vendor_id;
+	u32 device = (__force u32)device_id;

I don't have much context, but just from reading this, shouldn't this be be32_to_cpu() instead?

I should have explained that in the commit message. The values are supposed to be in big endian. We compare to PCI ids. The code originally was taken from [1], which does the right thing. The next version will add this info to the commit message.

Quoted 6 lines

Best regards
Thomas

[1]
https://elixir.bootlin.com/linux/v6.0.5/source/drivers/video/fbdev/offb.c#L3
57

Thanks for the link. The commit message for that original change [2] indicates this was a fix on a Powerstation which happens to be a PowerPC aka big-endian. This this happens to work as intended, but not on little-endian machines. vendor_id is __be32 (big-endian) and you compare this to PCI_VENDOR_ID_ATI (0x1002) which is native-endian. I guess you see the problem.
See also [3] where a property is converted properly.

Thinking about it, instead of calling 'is_avivo(*vendor_p, *device_p)' I'd prefer something like 'is_avivo(be32_to_cpup(vendor_p), be32_to_cpup(device_p))', so there is no need to pass __be32 around.

Best regards,
Alexander

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
commit/?id=57a20d8fb0d2a05abe40abd6bb29e3f923721f1b
[3] https://elixir.bootlin.com/linux/v6.0.5/source/drivers/bus/fsl-mc/fsl-mc-bus.c#L1027

Quoted 9 lines
Quoted 9 lines

Best regards,
Alexander

Quoted 6 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -0
+

/* This will match most R5xx */
return (vendor == PCI_VENDOR_ID_ATI) &&

  	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
author maintainer
#5 lore raw

Re: [PATCH 1/2] drm/ofdrm: Cast PCI IDs to u32 for comparing

Hi

Am 28.10.22 um 08:33 schrieb Alexander Stein:

Quoted 73 lines

Hi Thomas,

Am Donnerstag, 27. Oktober 2022, 16:04:34 CEST schrieb Thomas Zimmermann:

Quoted 56 lines

* PGP Signed: 10/27/2022 at 04:04:34 PM

Hi

Am 27.10.22 um 15:07 schrieb Alexander Stein:

Quoted 38 lines

Hello Thomas,

Am Donnerstag, 27. Oktober 2022, 13:57:06 CEST schrieb Thomas Zimmermann:

Quoted 35 lines

Properties of 32-bit integers are returned from the OF device tree as type __be32. Cast PCI vendor and device IDs from __be32 to u32 before comparing them to constants. 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.

Link:
https://lore.kernel.org/dri-devel/[email protected]/ #
[1] ---

   drivers/gpu/drm/tiny/ofdrm.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/tiny/ofdrm.c +1 -1
index 0e1cc2369afcc..0da8b248ccc6e 100644
@@ -231,8 +231,11 @@ 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(__be32 vendor_id, __be32 device_id)
 
Quoted 7 lines

drivers/gpu/drm/tiny/ofdrm.c static u64 display_get_address_of(struct drm_device *dev, struct device_node *of · line 237

Quoted 4 lines
drivers/gpu/drm/tiny/ofdrm.c +2 -0
   {
 
+	u32 vendor = (__force u32)vendor_id;
+	u32 device = (__force u32)device_id;

I don't have much context, but just from reading this, shouldn't this be be32_to_cpu() instead?

I should have explained that in the commit message. The values are supposed to be in big endian. We compare to PCI ids. The code originally was taken from [1], which does the right thing. The next version will add this info to the commit message.

Quoted 6 lines

Best regards
Thomas

[1]
https://elixir.bootlin.com/linux/v6.0.5/source/drivers/video/fbdev/offb.c#L3
57

Thanks for the link. The commit message for that original change [2] indicates this was a fix on a Powerstation which happens to be a PowerPC aka big-endian. This this happens to work as intended, but not on little-endian machines. vendor_id is __be32 (big-endian) and you compare this to PCI_VENDOR_ID_ATI (0x1002) which is native-endian. I guess you see the problem.
See also [3] where a property is converted properly.

Quoted 3 lines

Thinking about it, instead of calling 'is_avivo(*vendor_p, *device_p)' I'd prefer something like 'is_avivo(be32_to_cpup(vendor_p), be32_to_cpup(device_p))', so there is no need to pass __be32 around.

Makes sense. Thanks for reviewing.

Best regards
Thomas

Quoted 21 lines

Best regards,
Alexander

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
commit/?id=57a20d8fb0d2a05abe40abd6bb29e3f923721f1b
[3] https://elixir.bootlin.com/linux/v6.0.5/source/drivers/bus/fsl-mc/fsl-mc-bus.c#L1027

Quoted 9 lines
Quoted 9 lines

Best regards,
Alexander

Quoted 6 lines
drivers/gpu/drm/tiny/ofdrm.c +1 -0
+
   	/* This will match most R5xx */
   	return (vendor == PCI_VENDOR_ID_ATI) &&
   	
   	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
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
author maintainer
#6 lore raw

PATCH 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 0da8b248ccc6e..b358da3840ad0 100644
@@ -436,21 +436,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;
 }
@@ -468,7 +468,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;
 }
@@ -627,11 +627,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