⇤ ← Revision 1 as of 2014-03-13 17:14:43
1875
Comment: Talk about style preferences, warn about devs using conflicting styles.
|
2081
|
Deletions are marked like this. | Additions are marked like this. |
Line 54: | Line 54: |
= Parens in return value = Ignore checkpatch.pl if it complains about parens around boolean expressions or ternary conditionals in return values, like this: {{{ return ((depth > 1) ? (depth - 1) : depth); }}} |
Over 80-character line tips
Breaking comment lines
When breaking up comment lines that are over 80-characters, make sure to use the correct multi-line comment style, which is either:
/* One line. * Two lines. */
or
/* * One line * Two lines. */
Different driver authors use different styles, so use the style that is most common in the driver.
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.
Breaking long math lines
When breaking up long math lines, make sure to break after an operator, like this:
really_long_function_call(other_long_function_call(variable) && yet_another_long_function_call(variable));
Parens in return value
Ignore checkpatch.pl if it complains about parens around boolean expressions or ternary conditionals in return values, like this:
return ((depth > 1) ? (depth - 1) : depth);