2019-08-15 12:17:03

by Herbert Xu

[permalink] [raw]
Subject: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

This patch fixes a printk format warning by replacing %p with %#lx
for dma_addr_t.

Signed-off-by: Herbert Xu <[email protected]>

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index d72e062..3095284 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -347,8 +347,8 @@ static int qm_mb(struct hisi_qm *qm, u8 cmd, dma_addr_t dma_addr, u16 queue,
struct qm_mailbox mailbox;
int ret = 0;

- dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
- cmd, dma_addr);
+ dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
+ queue, cmd, (unsigned long)dma_addr);

mailbox.w0 = cmd |
(op ? 0x1 << QM_MB_OP_SHIFT : 0) |
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


2019-08-15 14:19:17

by Zhou Wang

[permalink] [raw]
Subject: Re: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

On 2019/8/15 20:03, Herbert Xu wrote:
> This patch fixes a printk format warning by replacing %p with %#lx
> for dma_addr_t.
>
> Signed-off-by: Herbert Xu <[email protected]>
>
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index d72e062..3095284 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -347,8 +347,8 @@ static int qm_mb(struct hisi_qm *qm, u8 cmd, dma_addr_t dma_addr, u16 queue,
> struct qm_mailbox mailbox;
> int ret = 0;
>
> - dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
> - cmd, dma_addr);
> + dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
> + queue, cmd, (unsigned long)dma_addr);

Thanks. However, to be honest I can't get why we fix it like this.
Can you give me a clue?

>
> mailbox.w0 = cmd |
> (op ? 0x1 << QM_MB_OP_SHIFT : 0) |
>

2019-08-15 23:52:09

by Herbert Xu

[permalink] [raw]
Subject: [v2 PATCH] crypto: hisilicon - Fix warning on printing %p with dma_addr_t

This patch fixes a printk format warning by replacing %p with %#llx
for dma_addr_t.

Signed-off-by: Herbert Xu <[email protected]>

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index d72e062..cfb0210 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -347,8 +353,8 @@ static int qm_mb(struct hisi_qm *qm, u8 cmd, dma_addr_t dma_addr, u16 queue,
struct qm_mailbox mailbox;
int ret = 0;

- dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
- cmd, dma_addr);
+ dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#llxad\n",
+ queue, cmd, (unsigned long long)dma_addr);

mailbox.w0 = cmd |
(op ? 0x1 << QM_MB_OP_SHIFT : 0) |
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-08-15 23:52:14

by Herbert Xu

[permalink] [raw]
Subject: Re: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

On Thu, Aug 15, 2019 at 10:17:37PM +0800, Zhou Wang wrote:
>
> > - dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
> > - cmd, dma_addr);
> > + dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
> > + queue, cmd, (unsigned long)dma_addr);
>
> Thanks. However, to be honest I can't get why we fix it like this.
> Can you give me a clue?

dma_addr_t is not a pointer. It's an integer type and therefore
you need to print it out as such.

Actually my patch is buggy too, on some architectures it can be
a long long so we need to cast is such.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-08-16 07:03:03

by Ondrej Mosnáček

[permalink] [raw]
Subject: Re: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

Hi Herbert,

pi 16. 8. 2019 o 1:52 Herbert Xu <[email protected]> napísal(a):
> On Thu, Aug 15, 2019 at 10:17:37PM +0800, Zhou Wang wrote:
> >
> > > - dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
> > > - cmd, dma_addr);
> > > + dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
> > > + queue, cmd, (unsigned long)dma_addr);
> >
> > Thanks. However, to be honest I can't get why we fix it like this.
> > Can you give me a clue?
>
> dma_addr_t is not a pointer. It's an integer type and therefore
> you need to print it out as such.

According to Documentation/core-api/printk-formats.rst, %pad is the
format specifier intended specifically for dma_addr_t [1], so perhaps
the kbuild robot warning was in fact bogus?

[1] https://www.kernel.org/doc/html/latest/core-api/printk-formats.html#dma-address-types-dma-addr-t

>
> Actually my patch is buggy too, on some architectures it can be
> a long long so we need to cast is such.
>
> Cheers,
> --
> Email: Herbert Xu <[email protected]>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-08-16 07:09:09

by Ondrej Mosnáček

[permalink] [raw]
Subject: Re: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

pi 16. 8. 2019 o 9:02 Ondrej Mosnáček <[email protected]> napísal(a):
> Hi Herbert,
>
> pi 16. 8. 2019 o 1:52 Herbert Xu <[email protected]> napísal(a):
> > On Thu, Aug 15, 2019 at 10:17:37PM +0800, Zhou Wang wrote:
> > >
> > > > - dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
> > > > - cmd, dma_addr);
> > > > + dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
> > > > + queue, cmd, (unsigned long)dma_addr);
> > >
> > > Thanks. However, to be honest I can't get why we fix it like this.
> > > Can you give me a clue?
> >
> > dma_addr_t is not a pointer. It's an integer type and therefore
> > you need to print it out as such.
>
> According to Documentation/core-api/printk-formats.rst, %pad is the
> format specifier intended specifically for dma_addr_t [1], so perhaps
> the kbuild robot warning was in fact bogus?
>
> [1] https://www.kernel.org/doc/html/latest/core-api/printk-formats.html#dma-address-types-dma-addr-t

Oh, wait, in that section it actually says "Passed by reference.", so
Zhou is most likely right that the proper fix is to pass a pointer to
the variable containing the address (I assume this is to make the
generic GCC's format checking pass even if dma_addr_t is not actually
a pointer).

>
> >
> > Actually my patch is buggy too, on some architectures it can be
> > a long long so we need to cast is such.
> >
> > Cheers,
> > --
> > Email: Herbert Xu <[email protected]>
> > Home Page: http://gondor.apana.org.au/~herbert/
> > PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-08-16 07:54:21

by Zhou Wang

[permalink] [raw]
Subject: Re: crypto: hisilicon - Fix warning on printing %p with dma_addr_t

On 2019/8/16 15:08, Ondrej Mosnáček wrote:
> pi 16. 8. 2019 o 9:02 Ondrej Mosnáček <[email protected]> napísal(a):
>> Hi Herbert,
>>
>> pi 16. 8. 2019 o 1:52 Herbert Xu <[email protected]> napísal(a):
>>> On Thu, Aug 15, 2019 at 10:17:37PM +0800, Zhou Wang wrote:
>>>>
>>>>> - dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%pad\n", queue,
>>>>> - cmd, dma_addr);
>>>>> + dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%#lxad\n",
>>>>> + queue, cmd, (unsigned long)dma_addr);
>>>>
>>>> Thanks. However, to be honest I can't get why we fix it like this.
>>>> Can you give me a clue?
>>>
>>> dma_addr_t is not a pointer. It's an integer type and therefore
>>> you need to print it out as such.
>>
>> According to Documentation/core-api/printk-formats.rst, %pad is the
>> format specifier intended specifically for dma_addr_t [1], so perhaps
>> the kbuild robot warning was in fact bogus?
>>
>> [1] https://www.kernel.org/doc/html/latest/core-api/printk-formats.html#dma-address-types-dma-addr-t
>
> Oh, wait, in that section it actually says "Passed by reference.", so
> Zhou is most likely right that the proper fix is to pass a pointer to
> the variable containing the address (I assume this is to make the
> generic GCC's format checking pass even if dma_addr_t is not actually
> a pointer).

Yes, I think you are right, I also mentioned this in v3.

Thanks,
Zhou

>
>>
>>>
>>> Actually my patch is buggy too, on some architectures it can be
>>> a long long so we need to cast is such.
>>>
>>> Cheers,
>>> --
>>> Email: Herbert Xu <[email protected]>
>>> Home Page: http://gondor.apana.org.au/~herbert/
>>> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
>
>