kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* newbies CheckpatchTips for multiline statements (Breaking function calls)
@ 2014-12-16 20:58 Joe Perches
  2014-12-16 21:17 ` Mandeep Sandhu
  2014-12-17  8:58 ` Bjørn Mork
  0 siblings, 2 replies; 4+ messages in thread
From: Joe Perches @ 2014-12-16 20:58 UTC (permalink / raw)
  To: kernelnewbies

http://kernelnewbies.org/CheckpatchTips

The block about "Breaking function calls" is dubious.

The majority of code today uses arguments aligned to parenthesis.
The suggested 1 tab is in fact very infrequently used.

CodingStyle has this as "substantially to the right", not 1 tab.

btw: there's a perferred/preferred tyop too.

------------

Breaking function calls

Sometimes a call to a function has several variables, and you need to
break the line in the middle of those variables. Look at this example: 

 
        pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN, GFP_KERNEL, &pdata->urb->transfer_dma);


This line is too long, so we want to break it up. By default, vim will
increase the indentation of the trailing line by one tab: 

        pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
                GFP_KERNEL, &pdata->urb->transfer_dma);


This style is fine, and generally perferred. However, some driver
writers prefer to have the trailing line of a function call line up with
the starting '('. They use tabs, followed by spaces, to align the
trailing line: 

 
        pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
                                            GFP_KERNEL,
                                            &pdata->urb->transfer_dma);


Again, the one tab indent style is preferred, but don't change lines
that use the other style. 

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

* newbies CheckpatchTips for multiline statements (Breaking function calls)
  2014-12-16 20:58 newbies CheckpatchTips for multiline statements (Breaking function calls) Joe Perches
@ 2014-12-16 21:17 ` Mandeep Sandhu
  2014-12-17  8:58 ` Bjørn Mork
  1 sibling, 0 replies; 4+ messages in thread
From: Mandeep Sandhu @ 2014-12-16 21:17 UTC (permalink / raw)
  To: kernelnewbies

>
> btw: there's a perferred/preferred tyop too.
>
Sorry, but I just couldn't ignore the irony of this. :P

-mandeep

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

* newbies CheckpatchTips for multiline statements (Breaking function calls)
  2014-12-16 20:58 newbies CheckpatchTips for multiline statements (Breaking function calls) Joe Perches
  2014-12-16 21:17 ` Mandeep Sandhu
@ 2014-12-17  8:58 ` Bjørn Mork
  2014-12-28  3:29   ` Anand Moon
  1 sibling, 1 reply; 4+ messages in thread
From: Bjørn Mork @ 2014-12-17  8:58 UTC (permalink / raw)
  To: kernelnewbies

Joe Perches <joe@perches.com> writes:

> This style is fine, and generally perferred. However, some driver
> writers prefer to have the trailing line of a function call line up with
> the starting '('. They use tabs, followed by spaces, to align the
> trailing line: 
>
>  
>         pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
>                                             GFP_KERNEL,
>                                             &pdata->urb->transfer_dma);

It might be worth noting that the network subsystem maintainer prefers
this style as well.  So most networking patches should probably use it.
The exception would be files which already use the other style.

You should also be aware of the implications of this style: You have to
modify all three lines if you change anything on the first line causing
the position of the starting '(' to change.  I.e., a patch like this is
not acceptable:

         -pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         +p->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
                                              GFP_KERNEL,
                                              &pdata->urb->transfer_dma);


It needs to be

         -pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         -                                    GFP_KERNEL,
         -                                    &pdata->urb->transfer_dma);
         +p->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         +                                GFP_KERNEL,
         +                                &pdata->urb->transfer_dma);


Bj?rn

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

* newbies CheckpatchTips for multiline statements (Breaking function calls)
  2014-12-17  8:58 ` Bjørn Mork
@ 2014-12-28  3:29   ` Anand Moon
  0 siblings, 0 replies; 4+ messages in thread
From: Anand Moon @ 2014-12-28  3:29 UTC (permalink / raw)
  To: kernelnewbies

Hi All,

If we are using the correct plugin in vim. We could hardly face this 

situation indent of the Linux kernel code. 


Below link helps

http://www.vim.org/scripts/script.php?script_id=4369

-Anand Moon


On Wednesday, December 17, 2014 4:25 PM, Bj?rn Mork <bjorn@mork.no> wrote:



Joe Perches <joe@perches.com> writes:

> This style is fine, and generally perferred. However, some driver
> writers prefer to have the trailing line of a function call line up with
> the starting '('. They use tabs, followed by spaces, to align the
> trailing line: 
>
>  
>         pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
>                                             GFP_KERNEL,
>                                             &pdata->urb->transfer_dma);

It might be worth noting that the network subsystem maintainer prefers
this style as well.  So most networking patches should probably use it.
The exception would be files which already use the other style.

You should also be aware of the implications of this style: You have to
modify all three lines if you change anything on the first line causing
the position of the starting '(' to change.  I.e., a patch like this is
not acceptable:

         -pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         +p->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
                                              GFP_KERNEL,
                                              &pdata->urb->transfer_dma);


It needs to be

         -pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         -                                    GFP_KERNEL,
         -                                    &pdata->urb->transfer_dma);
         +p->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
         +                                GFP_KERNEL,
         +                                &pdata->urb->transfer_dma);


Bj?rn

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2014-12-28  3:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-16 20:58 newbies CheckpatchTips for multiline statements (Breaking function calls) Joe Perches
2014-12-16 21:17 ` Mandeep Sandhu
2014-12-17  8:58 ` Bjørn Mork
2014-12-28  3:29   ` Anand Moon

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).