GPIO fixes for the v3.17 series:

- Some documentation sync
 - Resource leak in the bt8xx driver
 - Again fix the way varargs are used to handle the
   optional flags on the gpiod_* accessors. Now hopefully
   nailed the entire problem.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJUCXZqAAoJEEEQszewGV1zn5kP/19NJ4N7jUpaRIiL9yVEeOpB
 oKDceHRu4jRddgNndaAPjON+PwMLgYft4uDvPeY1ulObjPEPQUg39iFtTCWeJjcT
 Kzi1rhcJB5Qzepw78vcrFLfTPgXnObV1JweGnTtUhpBfbmVuCruSP6Iy2EsPMjR+
 zS1UA6sCe8hevOsVrF+CRCVgWbm1dntOiOsZyjRPXQCyafMv5EyMdaFSIbzIEWsf
 dxEFJ/3iFHtRrA2CUHpfg9vZO+v9rJ39tjRDNt3m0dOQkanys1zseolJUlCiM3Gf
 SnPFXxpxOpW+NyXW/d6wwlSfaJ/4RZ43KCBckHDGsCnEOd2SR+7sln+irwiNQ/gh
 tT0KcEixqT/06Tv1I6mC9JLTBffvqOEU8oMG5OyWNJvjq+WfBhyxo688q/pDURiJ
 Q7kPsFdIvoY5bvkrQFQ46xNnYdNwBKLJIeaJIp+Kf/ScnDMPtxO/DR1LNamb8Cnz
 YarxC1ZJb0OXqlFK3JG55gmjUEp8pnPjAMcMadqALmw4bKMWGvgmYfLp1U56TFZq
 ovQSBiASH0buAlAkdY4L8X12wmj5ScUyvy+3leQz65Xo4vktXZ/vdkjGzaNWMsPC
 o5MSkuUZkb76FuncXI/dicvJNlCe9GHceOfEMgflVZbGI+etDczI9/wDHgylKY9k
 /VeZgli8XiDMo/LNGkch
 =W9J2
 -----END PGP SIGNATURE-----

Merge tag 'gpio-v3.17-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO fixes from Linus Walleij:
 - some documentation sync
 - resource leak in the bt8xx driver
 - again fix the way varargs are used to handle the optional flags on
   the gpiod_* accessors.  Now hopefully nailed the entire problem.

* tag 'gpio-v3.17-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio:
  gpio: move varargs hack outside #ifdef GPIOLIB
  gpio: bt8xx: fix release of managed resources
  Documentation: gpio: documentation for optional getters functions
This commit is contained in:
Linus Torvalds 2014-09-05 08:04:29 -07:00
Родитель caa552358e 0dbc8b7afe
Коммит 5e6c72396c
3 изменённых файлов: 83 добавлений и 49 удалений

Просмотреть файл

@ -53,7 +53,20 @@ with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned
if and only if no GPIO has been assigned to the device/function/index triplet, if and only if no GPIO has been assigned to the device/function/index triplet,
other error codes are used for cases where a GPIO has been assigned but an error other error codes are used for cases where a GPIO has been assigned but an error
occurred while trying to acquire it. This is useful to discriminate between mere occurred while trying to acquire it. This is useful to discriminate between mere
errors and an absence of GPIO for optional GPIO parameters. errors and an absence of GPIO for optional GPIO parameters. For the common
pattern where a GPIO is optional, the gpiod_get_optional() and
gpiod_get_index_optional() functions can be used. These functions return NULL
instead of -ENOENT if no GPIO has been assigned to the requested function:
struct gpio_desc *gpiod_get_optional(struct device *dev,
const char *con_id,
enum gpiod_flags flags)
struct gpio_desc *gpiod_get_index_optional(struct device *dev,
const char *con_id,
unsigned int index,
enum gpiod_flags flags)
Device-managed variants of these functions are also defined: Device-managed variants of these functions are also defined:
@ -65,6 +78,15 @@ Device-managed variants of these functions are also defined:
unsigned int idx, unsigned int idx,
enum gpiod_flags flags) enum gpiod_flags flags)
struct gpio_desc *devm_gpiod_get_optional(struct device *dev,
const char *con_id,
enum gpiod_flags flags)
struct gpio_desc * devm_gpiod_get_index_optional(struct device *dev,
const char *con_id,
unsigned int index,
enum gpiod_flags flags)
A GPIO descriptor can be disposed of using the gpiod_put() function: A GPIO descriptor can be disposed of using the gpiod_put() function:
void gpiod_put(struct gpio_desc *desc) void gpiod_put(struct gpio_desc *desc)

Просмотреть файл

@ -241,9 +241,6 @@ static void bt8xxgpio_remove(struct pci_dev *pdev)
bgwrite(~0x0, BT848_INT_STAT); bgwrite(~0x0, BT848_INT_STAT);
bgwrite(0x0, BT848_GPIO_OUT_EN); bgwrite(0x0, BT848_GPIO_OUT_EN);
iounmap(bg->mmio);
release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
pci_disable_device(pdev); pci_disable_device(pdev);
} }

Просмотреть файл

@ -38,60 +38,32 @@ enum gpiod_flags {
struct gpio_desc *__must_check __gpiod_get(struct device *dev, struct gpio_desc *__must_check __gpiod_get(struct device *dev,
const char *con_id, const char *con_id,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __gpiod_get_index(dev, con_id, index, flags, ...) \
__gpiod_get_index(dev, con_id, index, flags)
#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
const char *con_id, const char *con_id,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __gpiod_get_optional(dev, con_id, flags, ...) \
__gpiod_get_optional(dev, con_id, flags)
#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
const char *con_id, const char *con_id,
unsigned int index, unsigned int index,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
__gpiod_get_index_optional(dev, con_id, index, flags)
#define gpiod_get_index_optional(varargs...) \
__gpiod_get_index_optional(varargs, 0)
void gpiod_put(struct gpio_desc *desc); void gpiod_put(struct gpio_desc *desc);
struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
const char *con_id, const char *con_id,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __devm_gpiod_get(dev, con_id, flags, ...) \
__devm_gpiod_get(dev, con_id, flags)
#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
__devm_gpiod_get_index(dev, con_id, index, flags)
#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
const char *con_id, const char *con_id,
enum gpiod_flags flags); enum gpiod_flags flags);
#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
__devm_gpiod_get_optional(dev, con_id, flags)
#define devm_gpiod_get_optional(varargs...) \
__devm_gpiod_get_optional(varargs, 0)
struct gpio_desc *__must_check struct gpio_desc *__must_check
__devm_gpiod_get_index_optional(struct device *dev, const char *con_id, __devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index, enum gpiod_flags flags); unsigned int index, enum gpiod_flags flags);
#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
__devm_gpiod_get_index_optional(dev, con_id, index, flags)
#define devm_gpiod_get_index_optional(varargs...) \
__devm_gpiod_get_index_optional(varargs, 0)
void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
int gpiod_get_direction(const struct gpio_desc *desc); int gpiod_get_direction(const struct gpio_desc *desc);
@ -124,27 +96,31 @@ int desc_to_gpio(const struct gpio_desc *desc);
#else /* CONFIG_GPIOLIB */ #else /* CONFIG_GPIOLIB */
static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev,
const char *con_id) const char *con_id,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev, static inline struct gpio_desc *__must_check
const char *con_id, __gpiod_get_index(struct device *dev,
unsigned int idx) const char *con_id,
unsigned int idx,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
gpiod_get_optional(struct device *dev, const char *con_id) __gpiod_get_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
gpiod_get_index_optional(struct device *dev, const char *con_id, __gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index) unsigned int index, enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
@ -157,28 +133,33 @@ static inline void gpiod_put(struct gpio_desc *desc)
WARN_ON(1); WARN_ON(1);
} }
static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, static inline struct gpio_desc *__must_check
const char *con_id) __devm_gpiod_get(struct device *dev,
const char *con_id,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline static inline
struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, struct gpio_desc *__must_check
const char *con_id, __devm_gpiod_get_index(struct device *dev,
unsigned int idx) const char *con_id,
unsigned int idx,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
devm_gpiod_get_optional(struct device *dev, const char *con_id) __devm_gpiod_get_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
devm_gpiod_get_index_optional(struct device *dev, const char *con_id, __devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index) unsigned int index, enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
@ -303,9 +284,43 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
return -EINVAL; return -EINVAL;
} }
#endif /* CONFIG_GPIOLIB */ #endif /* CONFIG_GPIOLIB */
/*
* Vararg-hacks! This is done to transition the kernel to always pass
* the options flags argument to the below functions. During a transition
* phase these vararg macros make both old-and-newstyle code compile,
* but when all calls to the elder API are removed, these should go away
* and the __gpiod_get() etc functions above be renamed just gpiod_get()
* etc.
*/
#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
#define __gpiod_get_index(dev, con_id, index, flags, ...) \
__gpiod_get_index(dev, con_id, index, flags)
#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
#define __gpiod_get_optional(dev, con_id, flags, ...) \
__gpiod_get_optional(dev, con_id, flags)
#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
__gpiod_get_index_optional(dev, con_id, index, flags)
#define gpiod_get_index_optional(varargs...) \
__gpiod_get_index_optional(varargs, 0)
#define __devm_gpiod_get(dev, con_id, flags, ...) \
__devm_gpiod_get(dev, con_id, flags)
#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
__devm_gpiod_get_index(dev, con_id, index, flags)
#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
__devm_gpiod_get_optional(dev, con_id, flags)
#define devm_gpiod_get_optional(varargs...) \
__devm_gpiod_get_optional(varargs, 0)
#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
__devm_gpiod_get_index_optional(dev, con_id, index, flags)
#define devm_gpiod_get_index_optional(varargs...) \
__devm_gpiod_get_index_optional(varargs, 0)
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
int gpiod_export(struct gpio_desc *desc, bool direction_may_change); int gpiod_export(struct gpio_desc *desc, bool direction_may_change);