From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Mon, 10 Oct 2011 13:51:30 -0400 Subject: [U-Boot] [PATCH V3 05/13] i2c: Create common default i2c_set_bus_num() function In-Reply-To: <4E930FDB.2000202@denx.de> References: <1318091769-30979-1-git-send-email-sbabic@denx.de> <201110101119.48636.vapier@gentoo.org> <4E930FDB.2000202@denx.de> Message-ID: <201110101351.31460.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Monday 10 October 2011 11:31:39 Stefano Babic wrote: > On 10/10/2011 05:19 PM, Mike Frysinger wrote: > > On Monday 10 October 2011 06:50:12 Stefano Babic wrote: > >> +int __def_i2c_set_bus_num(unsigned int bus) > >> +{ > >> + return 0; > >> +} > >> +int i2c_set_bus_num(unsigned int) > >> + __attribute__((weak, alias("__def_i2c_set_bus_num"))); > > > > any reason this can't just be: > > __weak int i2c_set_bus_num(unsigned int bus) > > { > > > > return 0; > > > > } > > > > i can understand having a default func when it actually does something, > > but i don't see much value in a stub that returns 0 > > It seems to me that this is the commonly used style in u-boot. The same > happens for the i2c_init_board, some lines before, and in a lot of other > modules: > > void __def_i2c_init_board(void) > { > return; > } > void i2c_init_board(void) > __attribute__((weak, alias("__def_i2c_init_board"))); > > Simply grepping in u-boot code, the default function is defined even if > it does nothing, i believe we have two standards. i'm not sure which gets used more, or if it's just a wash. i think it makes sense to have an accessible default func if it does something useful, but not if it's just a stub. in the __def/weak style above, unless people use --gc-sections when linking (i think we've got many people doing this now, but not all), you end up with dead code in the binary. in the code i proposed, the func gets discarded both when using --gc-sections and when not. -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20111010/836d1287/attachment.pgp