* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
@ 2015-02-02 19:26 Bas Peters
2015-02-02 19:34 ` Jeff Haran
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Bas Peters @ 2015-02-02 19:26 UTC (permalink / raw)
To: kernelnewbies
Hi,
I was checking some code in drivers/isdn/isdn_pp and came across the following:
case PPP_VJC_COMP:
if (is->debug & 0x20)
printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
{
struct sk_buff *skb_old = skb;
int pkt_len;
skb = dev_alloc_skb(skb_old->len + 128);
if (!skb) {
printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
skb = skb_old;
goto drop_packet;
}
skb_put(skb, skb_old->len + 128);
skb_copy_from_linear_data(skb_old, skb->data,
skb_old->len);
if (net_dev->local->ppp_slot < 0) {
printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
__func__, net_dev->local->ppp_slot);
goto drop_packet;
}
pkt_len = slhc_uncompress(ippp_table[net_dev->local->ppp_slot]->slcomp,
skb->data, skb_old->len);
kfree_skb(skb_old);
if (pkt_len < 0)
goto drop_packet;
skb_trim(skb, pkt_len);
skb->protocol = htons(ETH_P_IP);
}
break;
Could you explain to me why there are braces AFTER the printk invocation? Was it perhaps intended that the printk was included in the braces?
I'm sorry if I'm missing something completely obvious here, but it seems kind of strange to me.
With kind regards,
Bas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
2015-02-02 19:26 Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c Bas Peters
@ 2015-02-02 19:34 ` Jeff Haran
2015-02-02 19:36 ` Bas Peters
2015-02-02 19:35 ` Greg KH
2015-02-02 20:20 ` anish singh
2 siblings, 1 reply; 6+ messages in thread
From: Jeff Haran @ 2015-02-02 19:34 UTC (permalink / raw)
To: kernelnewbies
> -----Original Message-----
> From: kernelnewbies-bounces at kernelnewbies.org [mailto:kernelnewbies-
> bounces at kernelnewbies.org] On Behalf Of Bas Peters
> Sent: Monday, February 02, 2015 11:26 AM
> To: kernelnewbies at kernelnewbies.org; isdn at linux-pingi.de
> Subject: Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
>
> Hi,
>
> I was checking some code in drivers/isdn/isdn_pp and came across the
> following:
>
> case PPP_VJC_COMP:
> if (is->debug & 0x20)
> printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
> {
> struct sk_buff *skb_old = skb;
> int pkt_len;
> skb = dev_alloc_skb(skb_old->len + 128);
>
> if (!skb) {
> printk(KERN_WARNING "%s: Memory squeeze,
> dropping packet.\n", dev->name);
> skb = skb_old;
> goto drop_packet;
> }
> skb_put(skb, skb_old->len + 128);
> skb_copy_from_linear_data(skb_old, skb->data,
> skb_old->len);
> if (net_dev->local->ppp_slot < 0) {
> printk(KERN_ERR "%s: net_dev->local-
> >ppp_slot(%d) out of range\n",
> __func__, net_dev->local->ppp_slot);
> goto drop_packet;
> }
> pkt_len = slhc_uncompress(ippp_table[net_dev->local-
> >ppp_slot]->slcomp,
> skb->data, skb_old->len);
> kfree_skb(skb_old);
> if (pkt_len < 0)
> goto drop_packet;
>
> skb_trim(skb, pkt_len);
> skb->protocol = htons(ETH_P_IP);
> }
> break;
>
> Could you explain to me why there are braces AFTER the printk invocation?
> Was it perhaps intended that the printk was included in the braces?
>
> I'm sorry if I'm missing something completely obvious here, but it seems kind of
> strange to me.
>
> With kind regards,
>
> Bas
I assume it's just to introduce a new name space scope inside the case statement without going to the trouble of writing a new function that would be called from it.
Jeff Haran
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
2015-02-02 19:26 Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c Bas Peters
2015-02-02 19:34 ` Jeff Haran
@ 2015-02-02 19:35 ` Greg KH
2015-02-02 20:14 ` Henry Hallam
2015-02-02 20:20 ` anish singh
2 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2015-02-02 19:35 UTC (permalink / raw)
To: kernelnewbies
On Mon, Feb 02, 2015 at 08:26:26PM +0100, Bas Peters wrote:
> Hi,
>
> I was checking some code in drivers/isdn/isdn_pp and came across the following:
>
> case PPP_VJC_COMP:
> if (is->debug & 0x20)
> printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
> {
> struct sk_buff *skb_old = skb;
> int pkt_len;
> skb = dev_alloc_skb(skb_old->len + 128);
>
> if (!skb) {
> printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
> skb = skb_old;
> goto drop_packet;
> }
> skb_put(skb, skb_old->len + 128);
> skb_copy_from_linear_data(skb_old, skb->data,
> skb_old->len);
> if (net_dev->local->ppp_slot < 0) {
> printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
> __func__, net_dev->local->ppp_slot);
> goto drop_packet;
> }
> pkt_len = slhc_uncompress(ippp_table[net_dev->local->ppp_slot]->slcomp,
> skb->data, skb_old->len);
> kfree_skb(skb_old);
> if (pkt_len < 0)
> goto drop_packet;
>
> skb_trim(skb, pkt_len);
> skb->protocol = htons(ETH_P_IP);
> }
> break;
>
> Could you explain to me why there are braces AFTER the printk
> invocation? Was it perhaps intended that the printk was included in
> the braces?
Nope, the printk is for a debugging flag.
The braces afterward is for the new variable scope, it's odd looking
yes, but correct code and formatting.
Hope this helps,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
2015-02-02 19:34 ` Jeff Haran
@ 2015-02-02 19:36 ` Bas Peters
0 siblings, 0 replies; 6+ messages in thread
From: Bas Peters @ 2015-02-02 19:36 UTC (permalink / raw)
To: kernelnewbies
Alright, that makes sense. Is it bad practice to do so? Would it make
sense to change this to improve readability?
2015-02-02 20:34 GMT+01:00 Jeff Haran <Jeff.Haran@citrix.com>:
>> -----Original Message-----
>> From: kernelnewbies-bounces at kernelnewbies.org [mailto:kernelnewbies-
>> bounces at kernelnewbies.org] On Behalf Of Bas Peters
>> Sent: Monday, February 02, 2015 11:26 AM
>> To: kernelnewbies at kernelnewbies.org; isdn at linux-pingi.de
>> Subject: Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
>>
>> Hi,
>>
>> I was checking some code in drivers/isdn/isdn_pp and came across the
>> following:
>>
>> case PPP_VJC_COMP:
>> if (is->debug & 0x20)
>> printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
>> {
>> struct sk_buff *skb_old = skb;
>> int pkt_len;
>> skb = dev_alloc_skb(skb_old->len + 128);
>>
>> if (!skb) {
>> printk(KERN_WARNING "%s: Memory squeeze,
>> dropping packet.\n", dev->name);
>> skb = skb_old;
>> goto drop_packet;
>> }
>> skb_put(skb, skb_old->len + 128);
>> skb_copy_from_linear_data(skb_old, skb->data,
>> skb_old->len);
>> if (net_dev->local->ppp_slot < 0) {
>> printk(KERN_ERR "%s: net_dev->local-
>> >ppp_slot(%d) out of range\n",
>> __func__, net_dev->local->ppp_slot);
>> goto drop_packet;
>> }
>> pkt_len = slhc_uncompress(ippp_table[net_dev->local-
>> >ppp_slot]->slcomp,
>> skb->data, skb_old->len);
>> kfree_skb(skb_old);
>> if (pkt_len < 0)
>> goto drop_packet;
>>
>> skb_trim(skb, pkt_len);
>> skb->protocol = htons(ETH_P_IP);
>> }
>> break;
>>
>> Could you explain to me why there are braces AFTER the printk invocation?
>> Was it perhaps intended that the printk was included in the braces?
>>
>> I'm sorry if I'm missing something completely obvious here, but it seems kind of
>> strange to me.
>>
>> With kind regards,
>>
>> Bas
>
> I assume it's just to introduce a new name space scope inside the case statement without going to the trouble of writing a new function that would be called from it.
>
> Jeff Haran
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
2015-02-02 19:35 ` Greg KH
@ 2015-02-02 20:14 ` Henry Hallam
0 siblings, 0 replies; 6+ messages in thread
From: Henry Hallam @ 2015-02-02 20:14 UTC (permalink / raw)
To: kernelnewbies
On Mon, Feb 2, 2015 at 11:35 AM, Greg KH <greg@kroah.com> wrote:
> The braces afterward is for the new variable scope, it's odd looking
> yes, but correct code and formatting.
Specifically, without the braces there'd be a compile error at the
declaration of the pkt_len and skb_old variables.
Henry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c
2015-02-02 19:26 Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c Bas Peters
2015-02-02 19:34 ` Jeff Haran
2015-02-02 19:35 ` Greg KH
@ 2015-02-02 20:20 ` anish singh
2 siblings, 0 replies; 6+ messages in thread
From: anish singh @ 2015-02-02 20:20 UTC (permalink / raw)
To: kernelnewbies
On Mon, Feb 2, 2015 at 11:26 AM, Bas Peters <baspeters93@gmail.com> wrote:
> Hi,
>
> I was checking some code in drivers/isdn/isdn_pp and came across the
> following:
>
> case PPP_VJC_COMP:
> if (is->debug & 0x20)
> printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
> {
> struct sk_buff *skb_old = skb;
> int pkt_len;
> skb = dev_alloc_skb(skb_old->len + 128);
>
> if (!skb) {
> printk(KERN_WARNING "%s: Memory squeeze,
> dropping packet.\n", dev->name);
> skb = skb_old;
> goto drop_packet;
> }
> skb_put(skb, skb_old->len + 128);
> skb_copy_from_linear_data(skb_old, skb->data,
> skb_old->len);
> if (net_dev->local->ppp_slot < 0) {
> printk(KERN_ERR "%s:
> net_dev->local->ppp_slot(%d) out of range\n",
> __func__, net_dev->local->ppp_slot);
> goto drop_packet;
> }
> pkt_len =
> slhc_uncompress(ippp_table[net_dev->local->ppp_slot]->slcomp,
> skb->data, skb_old->len);
> kfree_skb(skb_old);
> if (pkt_len < 0)
> goto drop_packet;
>
> skb_trim(skb, pkt_len);
> skb->protocol = htons(ETH_P_IP);
> }
> break;
>
> Could you explain to me why there are braces AFTER the printk invocation?
> Was it perhaps intended that the printk was included in the braces?
>
I think it is intended and in my opinion it is because he didn't want to
declare
the local variables at the beginning of the function. He probably wanted
that piece of code which is inside the braces as standalone.
>
> I'm sorry if I'm missing something completely obvious here, but it seems
> kind of strange to me.
>
> With kind regards,
>
> Bas
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150202/44c1679a/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-02-02 20:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-02 19:26 Question regarding strange-looking code in drivers/isdn/i4l/isdn_ppp.c Bas Peters
2015-02-02 19:34 ` Jeff Haran
2015-02-02 19:36 ` Bas Peters
2015-02-02 19:35 ` Greg KH
2015-02-02 20:14 ` Henry Hallam
2015-02-02 20:20 ` anish singh
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).