Re: [RFC][PATCH 2/2] hwmon: (w83627ehf) Add GPIO port 3 functionality

From: Guenter Roeck
Date: Sat Jan 14 2012 - 12:56:30 EST


Alex,

On Fri, Jan 13, 2012 at 08:39:56PM -0500, Alex Rio wrote:
> The w83627ehf chip has 5 GPIO ports, currently none of them is supported.
> This patch adds the GPIO port 3 driver with the following functions:
> set/get pin values, direction_in/out, set_debounce.
> The values are also available to the userspace (if requiered)
> in the path /sys/class/gpio by using the export/unexport functions.
> Please look at the REVISIT comment, this is the main reason of the RFC,
> suggestions will be highly appreciated.
>
> Signed-off-by: Alex Rio <scasbyte@xxxxxxxxx>
> ---

[ ... ]

> +/* REVISIT!: This is a global variable for sioreg.
> + * How could a function like gpio_get be able to access
> + * sioreg from w83627ehf_sio_data?
> + * Maybe we can make the sioreg global?
> + */
> +int global_sioaddr;
> +

This is a complete no-go, even more so since the variable name is very generic
and visible in the entire kernel. Define the variables you need as part of
a structure for which you get a pointer to, then use container_of()
to get the pointer to the outer data structure. Other gpio drivers
do this already; just look there for examples.

Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/