[U-Boot] Question about Coding-Style

Wolfgang Denk wd at denx.de
Tue Feb 4 21:32:09 CET 2014


Dear Hannes,

In message <29703.213.33.116.113.1391525447.squirrel at petermaier.org> you wrote:
> 
> The 80 character thing is reported from checkpatch.pl as WARNING, not as
> ERROR - so there will be a chance of the patch to become accepted by a
> custodian.

It is better for your reputation ere on the list not to try to sneak
poorly formatted code in.  Just play by the rules, and these include
to fix such warnings issues by checkpatch.

> In between i tried to reformat by Code to obey to these rules, but now
> checkpatch.pl tells me following:
> 
> WARNING: Avoid unnecessary line continuations
> #531: FILE: board/BuR/bur_tseries/board.c:155:
> +	if (tps65217_voltage_update(TPS65217_DEFDCDC3, \
> 
> in real life the code section looks like this:
> /* Set DCDC3 (CORE) voltage to 1.125V */
> if (tps65217_voltage_update(TPS65217_DEFDCDC3, \
> 			TPS65217_DCDC_VOLT_SEL_1125MV)) {
> 	puts("tps65217_voltage_update failure\n");
> 	return;
> }
> 
> If i don't do the line break  at line 155 checkpatch.pl is disturbing me
> with the 80 character rule.

You can of course break the lines, but why do you put a backslash at
the end of the line?  It is this what checkpatch is complaining about:
"unnecessary line continuations".

> Another thing is linewrapping of output strings, to obey to the rules i
> have to format the string as following:
> 
> if (i2c_probe(TPS65217_CHIP_PM)) {
> 	printf("PMIC chip (0x%02x) not present! skipping" \
> 		"further configuration.\n", TPS65217_CHIP_PM);
> 	return;
> }

No.  printable strings shall not be broken, as you ay want to grep the
source code for that very string you see in your console log.

But then, it might make sense to think if you can cose a shorter form
of the text?  In the above case, the line is > 60 characters long
(BTW: you missed a space when breaking the string).  Is this needed?
For example:

	printf("ERROR: PMIC at 0x%02x missing\n", TPS65217_CHIP_PM);

gives the same information, actually even more prominent in the boot
log - and I don;t even have top break the line.

> But this makes it impossible to grep the code in case of an error.
> 
> Any idea how to deal with such things ?

Be creative, and use common sense.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
C++ was an interesting and valuable experiment, but we've learned its
lessons and it's time to move on.
                            - Peter Curran in <DCqM4z.BxB at isgtec.com>


More information about the U-Boot mailing list