On Fri, 2006-03-17 at 11:21 +0000, Bahadir Balban wrote: > Hi there, > > To access device registers, which one is best practice in terms of > coding style, and is any of them totally unacceptable for a driver to > be merged to the kernel? > > 1) Is this ok? > static inline unsigned int device_read_reg(int offset) > { > return readl(device_global_struct->base + offset); > } this sounds bad. Why? because this can only ever work with 1 piece of hardware. Can you 200% guarantee there never ever will be systems with 2 of your hardware? Also such wrappers are generally a bad idea, they just add no value other than obfuscating your code and making it harder to read. > 2) I've seen this in some kernel code, note the &: > readl(&device_global_struct->registeroffset); > writel(&device_global_struct->registeroffset, data); > > 3) Also possible: > readl(device_global_struct->registeroffset); > writel(device_global_struct->registeroffset, data); these are 2 different uses in the first case (2) device_global_struct is a *fake* pointer which "points" to the ioremap cookie. The "& ... -> .... " construct is a fancy way to write "+" to the compiler basically. in the second case (3) device_global_struct is a real structure, in which you stored the cookie itself. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/