Skip to contentSkip to conversation

crypto: ccp: Fix incorrect return type for psp_get_capability()

PATCH In review Yunseong Kim 3 participants 3 messages Sep 3, 2025 – Sep 8, 2025

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

PATCH 1/1 crypto: ccp: Fix incorrect return type for psp_get_capability()

psp_get_capability() is declared as returning an 'unsigned int'. However, it returns -ENODEV on failure when it cannot access the device registers (i.e., when ioread32 returns 0xffffffff).

Since -ENODEV is a negative value, returning it from a function declared as 'unsigned int' results in an implicit cast to a large positive integer. This prevents the caller psp_dev_init() from correctly detecting the error condition, leading to improper error handling.

Fix this by changing the return type of psp_get_capability() to 'int'.

Additionally, change the type of the local variable 'val' to 'u32', which is more appropriate for register access, and reformat the long dev_notice line to adhere to kernel coding style guidelines.

---
 drivers/crypto/ccp/psp-dev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/ccp/psp-dev.c +4 -3
index 1c5a7189631e..84dde53db25b 100644
@@ -140,9 +140,9 @@ static irqreturn_t psp_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static unsigned int psp_get_capability(struct psp_device *psp)
+static int psp_get_capability(struct psp_device *psp)
 {
-	unsigned int val = ioread32(psp->io_regs + psp->vdata->feature_reg);
+	u32 val = ioread32(psp->io_regs + psp->vdata->feature_reg);
 
 	/*
 	 * Check for a access to the registers.  If this read returns
@@ -152,7 +152,8 @@ static unsigned int psp_get_capability(struct psp_device *psp)
 	 * could get properly initialized).
 	 */
 	if (val == 0xffffffff) {
-		dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n");
+		dev_notice(psp->dev,
+			"psp: unable to access the device: you might be running a broken BIOS.\n");
 		return -ENODEV;
 	}
 	psp->capability.raw = val;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Yunseong Kim

psp_get_capability() is declared as returning an 'unsigned int'. However, it returns -ENODEV on failure when it cannot access the device registers (i.e., when ioread32 returns 0xffffffff).

Since -ENODEV is a negative value, returning it from a function declared as 'unsigned int' results in an implicit cast to a large positive integer. This prevents the caller psp_dev_init() from correctly detecting the error condition, leading to improper error handling.

Quoted 7 lines

Fix this by changing the return type of psp_get_capability() to 'int'.

Additionally, change the type of the local variable 'val' to 'u32', which is more appropriate for register access, and reformat the long dev_notice line to adhere to kernel coding style guidelines.

Quoted 30 lines
---
  drivers/crypto/ccp/psp-dev.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/ccp/psp-dev.c +4 -3
index 1c5a7189631e..84dde53db25b 100644
@@ -140,9 +140,9 @@ static irqreturn_t psp_irq_handler(int irq, void *data)
  	return IRQ_HANDLED;
  }
 
-static unsigned int psp_get_capability(struct psp_device *psp)
+static int psp_get_capability(struct psp_device *psp)
  {
-	unsigned int val = ioread32(psp->io_regs + psp->vdata->feature_reg);
+	u32 val = ioread32(psp->io_regs + psp->vdata->feature_reg);
 
  	/*
  	 * Check for a access to the registers.  If this read returns
@@ -152,7 +152,8 @@ static unsigned int psp_get_capability(struct psp_device *psp)
  	 * could get properly initialized).
  	 */
  	if (val == 0xffffffff) {
-		dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n");
+		dev_notice(psp->dev,
+			"psp: unable to access the device: you might be running a broken BIOS.\n");
  		return -ENODEV;
  	}
  	psp->capability.raw = val;
maintainer
#2 lore raw
In reply to Yunseong Kim
Quoted 4 lines · Yunseong Kim

psp_get_capability() is declared as returning an 'unsigned int'. However, it returns -ENODEV on failure when it cannot access the device registers (i.e., when ioread32 returns 0xffffffff).

Quoted 8 lines

Since -ENODEV is a negative value, returning it from a function declared as 'unsigned int' results in an implicit cast to a large positive integer. This prevents the caller psp_dev_init() from correctly detecting the error condition, leading to improper error handling.

Fix this by changing the return type of psp_get_capability() to 'int'.

Additionally, change the type of the local variable 'val' to 'u32', which

So you have a couple of changes going on here... which would mean separate patches. But since the raw field of psp_cap_register is an unsigned int and ioread32 returns an unsigned int, this doesn't need to be changed at all.

Quoted 13 lines

is more appropriate for register access, and reformat the long dev_notice line to adhere to kernel coding style guidelines.

---
 drivers/crypto/ccp/psp-dev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/ccp/psp-dev.c +0 -0
index 1c5a7189631e..84dde53db25b 100644

drivers/crypto/ccp/psp-dev.c static irqreturn_t psp_irq_handler(int irq, void *data) · line 143

Quoted 5 lines
drivers/crypto/ccp/psp-dev.c +1 -1
@@ -140,9 +140,9 @@ static irqreturn_t psp_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static unsigned int psp_get_capability(struct psp_device *psp)
+static int psp_get_capability(struct psp_device *psp)

This change is ok, everything else below is not needed.

Thanks,
Tom

Quoted 16 lines
drivers/crypto/ccp/psp-dev.c +3 -2
 {
-	unsigned int val = ioread32(psp->io_regs + psp->vdata->feature_reg);
+	u32 val = ioread32(psp->io_regs + psp->vdata->feature_reg);
 
 	/*
 	 * Check for a access to the registers.  If this read returns
@@ -152,7 +152,8 @@ static unsigned int psp_get_capability(struct psp_device *psp)
 	 * could get properly initialized).
 	 */
 	if (val == 0xffffffff) {
-		dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n");
+		dev_notice(psp->dev,
+			"psp: unable to access the device: you might be running a broken BIOS.\n");
 		return -ENODEV;
 	}
 	psp->capability.raw = val;