* Array subscript above array bounds warning
@ 2013-04-27 23:29 Tony Prisk
2013-04-27 23:54 ` Emilio López
0 siblings, 1 reply; 3+ messages in thread
From: Tony Prisk @ 2013-04-27 23:29 UTC (permalink / raw)
To: linux-arm-kernel
Could someone clarify for me what I am missing here?
in drivers/net/ethernet/via/velocity.h is the following definition:
struct mac_regs {
volatile u8 PAR[6]; /* 0x00 */
...
}
I am trying to add the following function but it keeps giving array
bounds warnings:
static void velocity_set_power_state(struct velocity_info *vptr, char state)
{
struct mac_regs __iomem *regs = vptr->mac_regs;
if (vptr->bustype == BUS_PCI) {
pci_set_power_state(vptr->pdev, state);
} else {
writeb(state, (®s->PAR[0]) + 0x154);
}
}
gives:
/home/sentient/linux-git/server/arch/arm/include/asm/io.h:83:2: warning:
array subscript is above array bounds [-Warray-bounds]
If I change the function to:
static void velocity_set_power_state(struct velocity_info *vptr, char state)
{
void __iomem *addr;
struct mac_regs __iomem *regs = vptr->mac_regs;
if (vptr->bustype == BUS_PCI)
pci_set_power_state(vptr->pdev, state);
else {
addr = ®s->PAR[0];
writeb(state, addr + 0x154);
}
}
I get the following warning:
drivers/net/ethernet/via/via-velocity.c:99:8: warning: assignment
discards ?volatile? qualifier from pointer target type [enabled by default]
What is the correct way to go about this?
Regards
Tony Prisk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Array subscript above array bounds warning
2013-04-27 23:29 Array subscript above array bounds warning Tony Prisk
@ 2013-04-27 23:54 ` Emilio López
2013-04-28 1:37 ` Tony Prisk
0 siblings, 1 reply; 3+ messages in thread
From: Emilio López @ 2013-04-27 23:54 UTC (permalink / raw)
To: linux-arm-kernel
El 27/04/13 20:29, Tony Prisk escribi?:
> Could someone clarify for me what I am missing here?
>
>
> in drivers/net/ethernet/via/velocity.h is the following definition:
>
> struct mac_regs {
> volatile u8 PAR[6]; /* 0x00 */
> ...
> }
>
> I am trying to add the following function but it keeps giving array
> bounds warnings:
>
> static void velocity_set_power_state(struct velocity_info *vptr, char
> state)
> {
> struct mac_regs __iomem *regs = vptr->mac_regs;
>
> if (vptr->bustype == BUS_PCI) {
> pci_set_power_state(vptr->pdev, state);
> } else {
> writeb(state, (®s->PAR[0]) + 0x154);
This would be equivalent to
writeb(state, regs->PAR + 0x154);
or
writeb(state, ®s->PAR[340]);
Which would be out of bounds, right? As it's an u8 array with just 6
elements, not 341+
^ permalink raw reply [flat|nested] 3+ messages in thread
* Array subscript above array bounds warning
2013-04-27 23:54 ` Emilio López
@ 2013-04-28 1:37 ` Tony Prisk
0 siblings, 0 replies; 3+ messages in thread
From: Tony Prisk @ 2013-04-28 1:37 UTC (permalink / raw)
To: linux-arm-kernel
On 28/04/13 11:54, Emilio L?pez wrote:
> El 27/04/13 20:29, Tony Prisk escribi?:
>> Could someone clarify for me what I am missing here?
>>
>>
>> in drivers/net/ethernet/via/velocity.h is the following definition:
>>
>> struct mac_regs {
>> volatile u8 PAR[6]; /* 0x00 */
>> ...
>> }
>>
>> I am trying to add the following function but it keeps giving array
>> bounds warnings:
>>
>> static void velocity_set_power_state(struct velocity_info *vptr, char
>> state)
>> {
>> struct mac_regs __iomem *regs = vptr->mac_regs;
>>
>> if (vptr->bustype == BUS_PCI) {
>> pci_set_power_state(vptr->pdev, state);
>> } else {
>> writeb(state, (®s->PAR[0]) + 0x154);
> This would be equivalent to
>
> writeb(state, regs->PAR + 0x154);
>
> or
>
> writeb(state, ®s->PAR[340]);
>
> Which would be out of bounds, right? As it's an u8 array with just 6
> elements, not 341+
Yeah sorry - stupid question.
I just thought about the code while out for a walk and realised I should
have looked at what the original author was trying to do rather than
copy it verbatim.I have solved the issue now.
Regards
Tony P
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-04-28 1:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-27 23:29 Array subscript above array bounds warning Tony Prisk
2013-04-27 23:54 ` Emilio López
2013-04-28 1:37 ` Tony Prisk
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).