[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABjd4YzRTPcy1nbhywuNLb0pz4gPVjhzegZJTc_g+_SVc1XJvw@mail.gmail.com>
Date: Wed, 30 Apr 2014 13:22:51 +0400
From: Alexey Charkov <alchark@...il.com>
To: David Laight <David.Laight@...lab.com>
Cc: Jan Moskyto Matejka <mq@...e.cz>, Roger Luethi <rl@...lgate.ch>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] net: via-rhine: fix compiler warning
2014-04-30 12:49 GMT+04:00 David Laight <David.Laight@...lab.com>:
> From: Jan Moskyto Matejka
>> Fixed different size cast warning:
>>
>> drivers/net/ethernet/via/via-rhine.c: In function rhine_init_one_platform:
>> drivers/net/ethernet/via/via-rhine.c:1132:13: warning: cast from pointer to integer of different
>> size [-Wpointer-to-int-cast]
>> revision = (u32)match->data;
>> ^
>>
>> That code was added in commit 2d283862dc62daead9db0dc89cd0d0351e91f765
>> ("net: via-rhine: add OF bus binding").
> ...
>> diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
>> index 4fa9201..76d18e0 100644
>> --- a/drivers/net/ethernet/via/via-rhine.c
>> +++ b/drivers/net/ethernet/via/via-rhine.c
>> @@ -288,7 +288,7 @@ MODULE_DEVICE_TABLE(pci, rhine_pci_tbl);
>> * (for quirks etc.)
>> */
>> static struct of_device_id rhine_of_tbl[] = {
>> - { .compatible = "via,vt8500-rhine", .data = (void *)0x84 },
>> + { .compatible = "via,vt8500-rhine", .data = (u32 []) { 0x84 } },
>> { } /* terminate list */
>> };
>> MODULE_DEVICE_TABLE(of, rhine_of_tbl);
>> @@ -1129,7 +1129,7 @@ static int rhine_init_one_platform(struct platform_device *pdev)
>> if (!irq)
>> return -EINVAL;
>>
>> - revision = (u32)match->data;
>> + revision = *((u32 *) match->data);
>> if (!revision)
>> return -EINVAL;
>
> Both those casts look horrid.
> I'm not entirely convinced that the first is valid C - It would have to be
> something specific to C99 initialisers.
> Casts like *(u32 *)foo are also likely to be bugs (esp. on BE systems)
> so themselves start ringing alarm bells.
>
> So why not just:
> revision = (unsigned long)match->data;
> and add a comment that the 0x84 is the revision - #define ??
There is no particular reason why it should be u32 now - this is a
leftover from the previous iteration of code where revision was a
separate property in DT (sized u32). It actually mirrors the
respective field in struct pci_dev, which is u8 - don't see any issue
defining it as unsigned long (and also changing the definition in
struct rhine_private).
The comment that it's the revision is right above the match table (cut
off in the patch) :)
Jan, would you prefer to adjust your patch, or shall I send another
one to change rp->revision and friends to unsigned long?
Thanks a lot,
Alexey
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists