* variant length array?
@ 2016-04-05 19:29 Wenda Ni
2016-04-05 19:43 ` Robert P. J. Day
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Wenda Ni @ 2016-04-05 19:29 UTC (permalink / raw)
To: kernelnewbies
Hi all,
I come across the following code in a kernel module code. It defines an
array whose length is variant at runtime, depending on the actual inputs.
It seems that kernel compiler supports this, which is obvious an error in
the standard ANSI C. Do I have the correct understanding on it?
Thank you.
u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
{
...
int hdr_size = sizeof(struct udphdr) +
(skb->protocol == htons(ETH_P_IP) ?
sizeof(struct iphdr) : sizeof(struct ipv6hdr));
u8 tmp[hdr_size + RXE_BTH_BYTES];
...
}
Cheers,
Wenda Ni, Ph.D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160405/faf2fc9e/attachment.html
^ permalink raw reply [flat|nested] 8+ messages in thread* variant length array?
2016-04-05 19:29 variant length array? Wenda Ni
@ 2016-04-05 19:43 ` Robert P. J. Day
2016-04-05 20:00 ` Bjørn Mork
2016-04-05 20:19 ` Valdis.Kletnieks at vt.edu
2016-04-06 10:51 ` Bernd Petrovitsch
2 siblings, 1 reply; 8+ messages in thread
From: Robert P. J. Day @ 2016-04-05 19:43 UTC (permalink / raw)
To: kernelnewbies
On Tue, 5 Apr 2016, Wenda Ni wrote:
> Hi all,
>
> I come across the following code in a kernel module code. It defines
> an array whose length is variant at runtime, depending on the actual
> inputs. It seems that kernel compiler supports this, which is
> obvious an error in the standard ANSI C. Do I have the correct
> understanding on it?
>
> Thank you.
>
>
> u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
> {
> ???????? ...
> ???????? int hdr_size = sizeof(struct udphdr) +
> ???????????????? (skb->protocol == htons(ETH_P_IP) ?
> ???????????????? sizeof(struct iphdr) : sizeof(struct ipv6hdr));
> ???????? u8 tmp[hdr_size + RXE_BTH_BYTES];
> ???????? ...
> }
pretty sure "sizeof" can be calculated at compile time so i don't
see a problem here.
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
^ permalink raw reply [flat|nested] 8+ messages in thread* variant length array?
2016-04-05 19:43 ` Robert P. J. Day
@ 2016-04-05 20:00 ` Bjørn Mork
2016-04-05 20:23 ` Rajat Sharma
2016-04-05 21:16 ` Robert P. J. Day
0 siblings, 2 replies; 8+ messages in thread
From: Bjørn Mork @ 2016-04-05 20:00 UTC (permalink / raw)
To: kernelnewbies
"Robert P. J. Day" <rpjday@crashcourse.ca> writes:
> On Tue, 5 Apr 2016, Wenda Ni wrote:
>
>> Hi all,
>>
>> I come across the following code in a kernel module code. It defines
>> an array whose length is variant at runtime, depending on the actual
>> inputs. It seems that kernel compiler supports this, which is
>> obvious an error in the standard ANSI C. Do I have the correct
>> understanding on it?
>>
>> Thank you.
>>
>>
>> u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>> {
>> ???????? ...
>> ???????? int hdr_size = sizeof(struct udphdr) +
>> ???????????????? (skb->protocol == htons(ETH_P_IP) ?
>> ???????????????? sizeof(struct iphdr) : sizeof(struct ipv6hdr));
>> ???????? u8 tmp[hdr_size + RXE_BTH_BYTES];
>> ???????? ...
>> }
>
> pretty sure "sizeof" can be calculated at compile time so i don't
> see a problem here.
Yes, but skb->protocol is variable and sizeof(struct iphdr) !=
sizeof(struct ipv6hdr)). Is the compiler smart enough to just use the
largest possible value? The logic here is pretty similar to a union,
which it of course wouldn't have any problems calculating the size of.
Bj?rn
^ permalink raw reply [flat|nested] 8+ messages in thread* variant length array?
2016-04-05 20:00 ` Bjørn Mork
@ 2016-04-05 20:23 ` Rajat Sharma
2016-04-05 21:16 ` Robert P. J. Day
1 sibling, 0 replies; 8+ messages in thread
From: Rajat Sharma @ 2016-04-05 20:23 UTC (permalink / raw)
To: kernelnewbies
On Tue, Apr 5, 2016 at 1:00 PM, Bj?rn Mork <bjorn@mork.no> wrote:
>
> "Robert P. J. Day" <rpjday@crashcourse.ca> writes:
> > On Tue, 5 Apr 2016, Wenda Ni wrote:
> >
> >> Hi all,
> >>
> >> I come across the following code in a kernel module code. It defines
> >> an array whose length is variant at runtime, depending on the actual
> >> inputs. It seems that kernel compiler supports this, which is
> >> obvious an error in the standard ANSI C. Do I have the correct
> >> understanding on it?
> >>
> >> Thank you.
> >>
> >>
> >> u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
> >> {
> >> ...
> >> int hdr_size = sizeof(struct udphdr) +
> >> (skb->protocol == htons(ETH_P_IP) ?
> >> sizeof(struct iphdr) : sizeof(struct ipv6hdr));
> >> u8 tmp[hdr_size + RXE_BTH_BYTES];
> >> ...
> >> }
> >
> > pretty sure "sizeof" can be calculated at compile time so i don't
> > see a problem here.
>
> Yes, but skb->protocol is variable and sizeof(struct iphdr) !=
> sizeof(struct ipv6hdr)). Is the compiler smart enough to just use the
> largest possible value? The logic here is pretty similar to a union,
> which it of course wouldn't have any problems calculating the size of.
>
>
> Bj?rn
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
It is actually a variable length array on stack. BTW nothing fancy
about kernel compiler, its GCC extention.
https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
-Rajat
^ permalink raw reply [flat|nested] 8+ messages in thread* variant length array?
2016-04-05 20:00 ` Bjørn Mork
2016-04-05 20:23 ` Rajat Sharma
@ 2016-04-05 21:16 ` Robert P. J. Day
1 sibling, 0 replies; 8+ messages in thread
From: Robert P. J. Day @ 2016-04-05 21:16 UTC (permalink / raw)
To: kernelnewbies
On Tue, 5 Apr 2016, Bj?rn Mork wrote:
> "Robert P. J. Day" <rpjday@crashcourse.ca> writes:
> > On Tue, 5 Apr 2016, Wenda Ni wrote:
> >
> >> Hi all,
> >>
> >> I come across the following code in a kernel module code. It defines
> >> an array whose length is variant at runtime, depending on the actual
> >> inputs. It seems that kernel compiler supports this, which is
> >> obvious an error in the standard ANSI C. Do I have the correct
> >> understanding on it?
> >>
> >> Thank you.
> >>
> >>
> >> u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
> >> {
> >> ???????? ...
> >> ???????? int hdr_size = sizeof(struct udphdr) +
> >> ???????????????? (skb->protocol == htons(ETH_P_IP) ?
> >> ???????????????? sizeof(struct iphdr) : sizeof(struct ipv6hdr));
> >> ???????? u8 tmp[hdr_size + RXE_BTH_BYTES];
> >> ???????? ...
> >> }
> >
> > pretty sure "sizeof" can be calculated at compile time so i don't
> > see a problem here.
>
> Yes, but skb->protocol is variable and sizeof(struct iphdr) !=
> sizeof(struct ipv6hdr)). Is the compiler smart enough to just use the
> largest possible value? The logic here is pretty similar to a union,
> which it of course wouldn't have any problems calculating the size of.
ah, quite so, i didn't look closely enough.
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
^ permalink raw reply [flat|nested] 8+ messages in thread
* variant length array?
2016-04-05 19:29 variant length array? Wenda Ni
2016-04-05 19:43 ` Robert P. J. Day
@ 2016-04-05 20:19 ` Valdis.Kletnieks at vt.edu
2016-04-05 20:29 ` Wenda Ni
2016-04-06 10:51 ` Bernd Petrovitsch
2 siblings, 1 reply; 8+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2016-04-05 20:19 UTC (permalink / raw)
To: kernelnewbies
On Tue, 05 Apr 2016 15:29:25 -0400, Wenda Ni said:
> I come across the following code in a kernel module code.
> u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
Is this an out-of-tree module, or an older kernel?
The current linux-next tree has zero occurences of 'rxe_icrc_hdr'
or 'rxe_pkt_info' in it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160405/26234844/attachment.bin
^ permalink raw reply [flat|nested] 8+ messages in thread
* variant length array?
2016-04-05 20:19 ` Valdis.Kletnieks at vt.edu
@ 2016-04-05 20:29 ` Wenda Ni
0 siblings, 0 replies; 8+ messages in thread
From: Wenda Ni @ 2016-04-05 20:29 UTC (permalink / raw)
To: kernelnewbies
On Tue, Apr 5, 2016 at 4:19 PM, <Valdis.Kletnieks@vt.edu> wrote:
> On Tue, 05 Apr 2016 15:29:25 -0400, Wenda Ni said:
>
> > I come across the following code in a kernel module code.
>
> > u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>
> Is this an out-of-tree module, or an older kernel?
>
> The current linux-next tree has zero occurences of 'rxe_icrc_hdr'
> or 'rxe_pkt_info' in it.
>
>
> You are right. It is an out-of-tree module, called softRoCE,
https://github.com/SoftRoCE/rxe-dev
uname -a gives kernel version to be 4.0.0+, I do not know exactly which
kernel base they use for development.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160405/95d80135/attachment.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* variant length array?
2016-04-05 19:29 variant length array? Wenda Ni
2016-04-05 19:43 ` Robert P. J. Day
2016-04-05 20:19 ` Valdis.Kletnieks at vt.edu
@ 2016-04-06 10:51 ` Bernd Petrovitsch
2 siblings, 0 replies; 8+ messages in thread
From: Bernd Petrovitsch @ 2016-04-06 10:51 UTC (permalink / raw)
To: kernelnewbies
Hi!
On Die, 2016-04-05 at 15:29 -0400, Wenda Ni wrote:
[...]
> I come across the following code in a kernel module code. It defines an
> array whose length is variant at runtime, depending on the actual inputs.
> It seems that kernel compiler supports this, which is obvious an error in
> the standard ANSI C. Do I have the correct understanding on it?
ANSI-C ist old and enforced with -std=c89 with gcc (see manual page).
VLAs are allowed since (standard) C99.
Bernd
--
"What happens when you read some doc and either it doesn't answer your
question or is demonstrably wrong? In Linux, you say "Linux sucks" and
go read the code. In Windows/Oracle/etc you say "Windows sucks" and
start banging your head against the wall." - Denis Vlasenko on lkml
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-04-06 10:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-05 19:29 variant length array? Wenda Ni
2016-04-05 19:43 ` Robert P. J. Day
2016-04-05 20:00 ` Bjørn Mork
2016-04-05 20:23 ` Rajat Sharma
2016-04-05 21:16 ` Robert P. J. Day
2016-04-05 20:19 ` Valdis.Kletnieks at vt.edu
2016-04-05 20:29 ` Wenda Ni
2016-04-06 10:51 ` Bernd Petrovitsch
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).