Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Yunseong Kim <ysk@kzalloc.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Mario Limonciello <mario.limonciello@amd.com>,
	John Allen <john.allen@amd.com>,
	"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ccp: Fix incorrect return type for psp_get_capability()
Date: Mon, 8 Sep 2025 11:10:11 -0500	[thread overview]
Message-ID: <78670082-36a2-2520-ac7f-b71482540035@amd.com> (raw)
In-Reply-To: <20250903135547.19617-2-ysk@kzalloc.com>

On 9/3/25 08:55, Yunseong Kim wrote:
> 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

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.

> is more appropriate for register access, and reformat the long dev_notice
> line to adhere to kernel coding style guidelines.
> 
> Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
> ---
>  drivers/crypto/ccp/psp-dev.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index 1c5a7189631e..84dde53db25b 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -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

>  {
> -	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;

      parent reply	other threads:[~2025-09-08 16:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03 13:55 [PATCH] crypto: ccp: Fix incorrect return type for psp_get_capability() Yunseong Kim
2025-09-03 14:53 ` Mario Limonciello
2025-09-08 16:10 ` Tom Lendacky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=78670082-36a2-2520-ac7f-b71482540035@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=ysk@kzalloc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox