Skip to contentSkip to conversation

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

PATCH In review Yunseong Kim 2 participants 3 messages Apr 26 – Apr 27

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

PATCH v2 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.

---
Changes in v2:
- Address feedback from Tom Lendacky.

---
 drivers/crypto/ccp/psp-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/psp-dev.c +1 -1
index 5c7f7e02a7d8..664cd51bbf0d 100644
@@ -141,7 +141,7 @@ 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);
 

---
base-commit: 7080e32d3f09d8688c4a87d81bdcc71f7f606b16
change-id: 20260426-master-eba8d68042ab

Best regards,

Signature · 1 line
Yunseong Kim <[email protected]>
maintainer
#1 lore raw
Quoted 10 lines · Yunseong Kim

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

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.

Not true. The psp_dev_init() function will assign the return value to an int and so it ends up getting the -ENODEV value in the end. Also, since psp_dev_init() is only checking for a non-zero value on error and the return value of psp_dev_init() is not checked, this doesn't have any impact on the processing or handling of errors.

I agree that psp_get_capability() should return an int instead of an unsigned int, so the patch is fine, but you need to rework the commit message to be accurate.

Thanks,
Tom

Quoted 31 lines

---
Changes in v2:
- Address feedback from Tom Lendacky.

---
 drivers/crypto/ccp/psp-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/psp-dev.c +1 -2
index 5c7f7e02a7d8..664cd51bbf0d 100644
@@ -141,7 +141,7 @@ 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);
 
 
---

base-commit: 7080e32d3f09d8688c4a87d81bdcc71f7f606b16
change-id: 20260426-master-eba8d68042ab

Best regards,
--
Yunseong Kim <[email protected]>

#2 lore raw

Hi Tom,

Quoted 18 lines · Tom Lendacky
Quoted 10 lines · Yunseong Kim

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

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.

Not true. The psp_dev_init() function will assign the return value to an int and so it ends up getting the -ENODEV value in the end. Also, since psp_dev_init() is only checking for a non-zero value on error and the return value of psp_dev_init() is not checked, this doesn't have any impact on the processing or handling of errors.

Quoted 6 lines

I agree that psp_get_capability() should return an int instead of an unsigned int, so the patch is fine, but you need to rework the commit message to be accurate.

Thanks,
Tom

Oh, I see. Thanks for the comment! I’ll fix this in v3, and sorry for being a bit late with the v2 patch.

Quoted 23 lines
Quoted 23 lines

---
Changes in v2:
- Address feedback from Tom Lendacky.

---
 drivers/crypto/ccp/psp-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/psp-dev.c +1 -1
index 5c7f7e02a7d8..664cd51bbf0d 100644
@@ -141,7 +141,7 @@ 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);
 
Quoted 8 lines
Quoted 8 lines

---
base-commit: 7080e32d3f09d8688c4a87d81bdcc71f7f606b16
change-id: 20260426-master-eba8d68042ab

Best regards,
--
Yunseong Kim <[email protected]>

Thank you,
Yunseong