linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/raid1-10: shut up randstruct warning again
@ 2023-06-16  9:24 Arnd Bergmann
  2023-06-16  9:30 ` Yu Kuai
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2023-06-16  9:24 UTC (permalink / raw)
  To: Song Liu, Yu Kuai
  Cc: Arnd Bergmann, Damien Le Moal, Jens Axboe, Johannes Thumshirn,
	linux-raid, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

A code reorganization brought back a warning when structure randomization
is enabled:

drivers/md/raid1-10.c:119:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
        struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
                               ^

Before the rework, this used a (void*) cast, so go back to that in order
to avoid the warning. Casting between pointers to incompatible types is
clearly something that is dangerous, but this driver has always done so,
and it's not made any worse by the struct randomization in this case.

Fixes: 8295efbe68c08 ("md/raid1-10: factor out a helper to submit normal write")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/md/raid1-10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 169ebe296f2d0..3f22edec70e78 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -116,7 +116,7 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
 
 static inline void raid1_submit_write(struct bio *bio)
 {
-	struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
+	struct md_rdev *rdev = (void *)bio->bi_bdev;
 
 	bio->bi_next = NULL;
 	bio_set_dev(bio, rdev->bdev);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] md/raid1-10: shut up randstruct warning again
  2023-06-16  9:24 [PATCH] md/raid1-10: shut up randstruct warning again Arnd Bergmann
@ 2023-06-16  9:30 ` Yu Kuai
  0 siblings, 0 replies; 2+ messages in thread
From: Yu Kuai @ 2023-06-16  9:30 UTC (permalink / raw)
  To: Arnd Bergmann, Song Liu
  Cc: Arnd Bergmann, Damien Le Moal, Jens Axboe, Johannes Thumshirn,
	linux-raid, linux-kernel, yukuai (C)

Hi,

在 2023/06/16 17:24, Arnd Bergmann 写道:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> A code reorganization brought back a warning when structure randomization
> is enabled:
> 
> drivers/md/raid1-10.c:119:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
>          struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
>                                 ^
> 
> Before the rework, this used a (void*) cast, so go back to that in order
> to avoid the warning. Casting between pointers to incompatible types is
> clearly something that is dangerous, but this driver has always done so,
> and it's not made any worse by the struct randomization in this case.
> 
> Fixes: 8295efbe68c08 ("md/raid1-10: factor out a helper to submit normal write")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for the patch, and this problem is already reported by kernel
test robot:

https://lore.kernel.org/oe-kbuild-all/202306142042.fmjfmTF8-lkp@intel.com/

And fixed patch is already applied:

https://lore.kernel.org/lkml/CAPhsuW6aSvCEa1khjjmDYGozUEs+Tx75RxfaE1+xL2Y1T6aN=Q@mail.gmail.com/T/

Thanks,
Kuai
> ---
>   drivers/md/raid1-10.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
> index 169ebe296f2d0..3f22edec70e78 100644
> --- a/drivers/md/raid1-10.c
> +++ b/drivers/md/raid1-10.c
> @@ -116,7 +116,7 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
>   
>   static inline void raid1_submit_write(struct bio *bio)
>   {
> -	struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
> +	struct md_rdev *rdev = (void *)bio->bi_bdev;
>   
>   	bio->bi_next = NULL;
>   	bio_set_dev(bio, rdev->bdev);
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-16  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-16  9:24 [PATCH] md/raid1-10: shut up randstruct warning again Arnd Bergmann
2023-06-16  9:30 ` Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).