2023-04-20 07:44:55

by Wu Yunchuan

[permalink] [raw]
Subject: [PATCH] firmware:Remove unnecessary (void*) conversions

Pointer variables of void * type do not require type cast.

Signed-off-by: yunchuan <[email protected]>
---
drivers/firmware/turris-mox-rwtm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index 6ea5789a89e2..af2fa620e6bc 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -283,7 +283,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm)

static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
- struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv;
+ struct mox_rwtm *rwtm = rng->priv;
struct armada_37xx_rwtm_tx_msg msg;
int ret;

--
2.30.2


2023-04-20 10:46:37

by Marek Behún

[permalink] [raw]
Subject: Re: [PATCH] firmware:Remove unnecessary (void*) conversions

This makes sense, but the commit title should be
firmware: turris-mox-rwtm: drop unnecessary (void *) conversion

On Thu, Apr 20, 2023 at 03:37:51PM +0800, yunchuan wrote:
> Pointer variables of void * type do not require type cast.
>
> Signed-off-by: yunchuan <[email protected]>
> ---
> drivers/firmware/turris-mox-rwtm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
> index 6ea5789a89e2..af2fa620e6bc 100644
> --- a/drivers/firmware/turris-mox-rwtm.c
> +++ b/drivers/firmware/turris-mox-rwtm.c
> @@ -283,7 +283,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
>
> static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
> {
> - struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv;
> + struct mox_rwtm *rwtm = rng->priv;
> struct armada_37xx_rwtm_tx_msg msg;
> int ret;
>
> --
> 2.30.2
>

2023-04-20 11:53:04

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] firmware:Remove unnecessary (void*) conversions

Hi yunchuan,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc7 next-20230419]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
patch link: https://lore.kernel.org/r/20230420073751.1031944-1-yunchuan%40nfschina.com
patch subject: [PATCH] firmware:Remove unnecessary (void*) conversions
config: hexagon-randconfig-r034-20230420 (https://download.01.org/0day-ci/archive/20230420/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/1dee3a7afbb402fc49f0af9eeb312f221e99fab6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
git checkout 1dee3a7afbb402fc49f0af9eeb312f221e99fab6
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/firmware/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/firmware/turris-mox-rwtm.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from drivers/firmware/turris-mox-rwtm.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from drivers/firmware/turris-mox-rwtm.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
>> drivers/firmware/turris-mox-rwtm.c:286:19: error: incompatible integer to pointer conversion initializing 'struct mox_rwtm *' with an expression of type 'unsigned long' [-Wint-conversion]
struct mox_rwtm *rwtm = rng->priv;
^ ~~~~~~~~~
6 warnings and 1 error generated.


vim +286 drivers/firmware/turris-mox-rwtm.c

283
284 static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
285 {
> 286 struct mox_rwtm *rwtm = rng->priv;
287 struct armada_37xx_rwtm_tx_msg msg;
288 int ret;
289
290 if (max > 4096)
291 max = 4096;
292
293 msg.command = MBOX_CMD_GET_RANDOM;
294 msg.args[0] = 1;
295 msg.args[1] = rwtm->buf_phys;
296 msg.args[2] = (max + 3) & ~3;
297
298 if (!wait) {
299 if (!mutex_trylock(&rwtm->busy))
300 return -EBUSY;
301 } else {
302 mutex_lock(&rwtm->busy);
303 }
304
305 ret = mbox_send_message(rwtm->mbox, &msg);
306 if (ret < 0)
307 goto unlock_mutex;
308
309 ret = wait_for_completion_interruptible(&rwtm->cmd_done);
310 if (ret < 0)
311 goto unlock_mutex;
312
313 ret = mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
314 if (ret < 0)
315 goto unlock_mutex;
316
317 memcpy(data, rwtm->buf, max);
318 ret = max;
319
320 unlock_mutex:
321 mutex_unlock(&rwtm->busy);
322 return ret;
323 }
324

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

2023-04-21 01:15:09

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] firmware:Remove unnecessary (void*) conversions

Hi yunchuan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc7 next-20230419]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
patch link: https://lore.kernel.org/r/20230420073751.1031944-1-yunchuan%40nfschina.com
patch subject: [PATCH] firmware:Remove unnecessary (void*) conversions
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230421/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/1dee3a7afbb402fc49f0af9eeb312f221e99fab6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
git checkout 1dee3a7afbb402fc49f0af9eeb312f221e99fab6
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/firmware/turris-mox-rwtm.c: In function 'mox_hwrng_read':
>> drivers/firmware/turris-mox-rwtm.c:286:33: warning: initialization of 'struct mox_rwtm *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
286 | struct mox_rwtm *rwtm = rng->priv;
| ^~~


vim +286 drivers/firmware/turris-mox-rwtm.c

283
284 static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
285 {
> 286 struct mox_rwtm *rwtm = rng->priv;
287 struct armada_37xx_rwtm_tx_msg msg;
288 int ret;
289
290 if (max > 4096)
291 max = 4096;
292
293 msg.command = MBOX_CMD_GET_RANDOM;
294 msg.args[0] = 1;
295 msg.args[1] = rwtm->buf_phys;
296 msg.args[2] = (max + 3) & ~3;
297
298 if (!wait) {
299 if (!mutex_trylock(&rwtm->busy))
300 return -EBUSY;
301 } else {
302 mutex_lock(&rwtm->busy);
303 }
304
305 ret = mbox_send_message(rwtm->mbox, &msg);
306 if (ret < 0)
307 goto unlock_mutex;
308
309 ret = wait_for_completion_interruptible(&rwtm->cmd_done);
310 if (ret < 0)
311 goto unlock_mutex;
312
313 ret = mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
314 if (ret < 0)
315 goto unlock_mutex;
316
317 memcpy(data, rwtm->buf, max);
318 ret = max;
319
320 unlock_mutex:
321 mutex_unlock(&rwtm->busy);
322 return ret;
323 }
324

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

2023-04-21 05:33:18

by Wu Yunchuan

[permalink] [raw]
Subject: Re: [PATCH] firmware:Remove unnecessary (void*) conversions


在 2023/4/20 19:49, kernel test robot 写道:
> Hi yunchuan,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on linus/master]
> [also build test ERROR on v6.3-rc7 next-20230419]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
> patch link: https://lore.kernel.org/r/20230420073751.1031944-1-yunchuan%40nfschina.com
> patch subject: [PATCH] firmware:Remove unnecessary (void*) conversions
> config: hexagon-randconfig-r034-20230420 (https://download.01.org/0day-ci/archive/20230420/[email protected]/config)
> compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # https://github.com/intel-lab-lkp/linux/commit/1dee3a7afbb402fc49f0af9eeb312f221e99fab6
> git remote add linux-review https://github.com/intel-lab-lkp/linux
> git fetch --no-tags linux-review yunchuan/firmware-Remove-unnecessary-void-conversions/20230420-154004
> git checkout 1dee3a7afbb402fc49f0af9eeb312f221e99fab6
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/firmware/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
> | Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> All errors (new ones prefixed by >>):
>
> In file included from drivers/firmware/turris-mox-rwtm.c:11:
> In file included from include/linux/dma-mapping.h:10:
> In file included from include/linux/scatterlist.h:9:
> In file included from arch/hexagon/include/asm/io.h:334:
> include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> val = __raw_readb(PCI_IOBASE + addr);
> ~~~~~~~~~~ ^
> include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
> ~~~~~~~~~~ ^
> include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
> #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
> ^
> In file included from drivers/firmware/turris-mox-rwtm.c:11:
> In file included from include/linux/dma-mapping.h:10:
> In file included from include/linux/scatterlist.h:9:
> In file included from arch/hexagon/include/asm/io.h:334:
> include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
> ~~~~~~~~~~ ^
> include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
> #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
> ^
> In file included from drivers/firmware/turris-mox-rwtm.c:11:
> In file included from include/linux/dma-mapping.h:10:
> In file included from include/linux/scatterlist.h:9:
> In file included from arch/hexagon/include/asm/io.h:334:
> include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> __raw_writeb(value, PCI_IOBASE + addr);
> ~~~~~~~~~~ ^
> include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
> ~~~~~~~~~~ ^
> include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
> ~~~~~~~~~~ ^
>>> drivers/firmware/turris-mox-rwtm.c:286:19: error: incompatible integer to pointer conversion initializing 'struct mox_rwtm *' with an expression of type 'unsigned long' [-Wint-conversion]
> struct mox_rwtm *rwtm = rng->priv;
> ^ ~~~~~~~~~
> 6 warnings and 1 error generated.


Yes, that's an oversight, 'priv' should be unsigned long variable.I
didn't pay attention to the structure definition in
'include/linux/hw_random.h'.

Thanks for your quick feedbacks and sorry for being late.


>
>
> vim +286 drivers/firmware/turris-mox-rwtm.c
>
> 283
> 284 static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
> 285 {
> > 286 struct mox_rwtm *rwtm = rng->priv;
> 287 struct armada_37xx_rwtm_tx_msg msg;
> 288 int ret;
> 289
> 290 if (max > 4096)
> 291 max = 4096;
> 292
> 293 msg.command = MBOX_CMD_GET_RANDOM;
> 294 msg.args[0] = 1;
> 295 msg.args[1] = rwtm->buf_phys;
> 296 msg.args[2] = (max + 3) & ~3;
> 297
> 298 if (!wait) {
> 299 if (!mutex_trylock(&rwtm->busy))
> 300 return -EBUSY;
> 301 } else {
> 302 mutex_lock(&rwtm->busy);
> 303 }
> 304
> 305 ret = mbox_send_message(rwtm->mbox, &msg);
> 306 if (ret < 0)
> 307 goto unlock_mutex;
> 308
> 309 ret = wait_for_completion_interruptible(&rwtm->cmd_done);
> 310 if (ret < 0)
> 311 goto unlock_mutex;
> 312
> 313 ret = mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
> 314 if (ret < 0)
> 315 goto unlock_mutex;
> 316
> 317 memcpy(data, rwtm->buf, max);
> 318 ret = max;
> 319
> 320 unlock_mutex:
> 321 mutex_unlock(&rwtm->busy);
> 322 return ret;
> 323 }
> 324
>

2023-04-21 07:31:09

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] firmware:Remove unnecessary (void*) conversions

Hi Yunchan,

On Thu, Apr 20, 2023 at 9:41 AM yunchuan <[email protected]> wrote:
> Pointer variables of void * type do not require type cast.
>
> Signed-off-by: yunchuan <[email protected]>

> --- a/drivers/firmware/turris-mox-rwtm.c
> +++ b/drivers/firmware/turris-mox-rwtm.c
> @@ -283,7 +283,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
>
> static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
> {
> - struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv;

hwrng.priv is unsigned long, so the cast is needed.
Please try to (at least) test-compile your changes.

NAKed-by: Geert Uytterhoeven <[email protected]>

> + struct mox_rwtm *rwtm = rng->priv;
> struct armada_37xx_rwtm_tx_msg msg;
> int ret;


Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds