Commit 4fb9a54c authored by Dimitris Lampridis's avatar Dimitris Lampridis Committed by Federico Vaga

kernel: fix kernel >4.4 compatibility

Compiling on kernel >=4.5 produces the following error:

  CC [M]  spec-sw/kernel/wr-nic-gpio.o
spec-sw/kernel/wr-nic-gpio.c: In function ‘gc_to_fmc’:
spec-sw/kernel/wr-nic-gpio.c:20:25: error: ‘struct gpio_chip’ has no member named ‘dev’
  struct device *dev = gc->dev;
                         ^
spec-sw/kernel/wr-nic-gpio.c: In function ‘wrn_gpio_init’:
spec-sw/kernel/wr-nic-gpio.c:75:4: error: ‘struct gpio_chip’ has no member named ‘dev’
  gc->dev = &fmc->dev;
    ^

This is due to a change in struct gpio_chip introduced in 4.5,
where the "dev" field was renamed to "parent".

58383c7 gpio: change member .dev to .parent

This patch makes our code compatible with modern kernel versions
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
Signed-off-by: 's avatarDimitris Lampridis <Dimitris.Lampridis@cern.ch>
parent 62898528
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* This work is part of the White Rabbit project, a research effort led * This work is part of the White Rabbit project, a research effort led
* by CERN, the European Institute for Nuclear Research. * by CERN, the European Institute for Nuclear Research.
*/ */
#include <linux/version.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/version.h> #include <linux/version.h>
...@@ -17,7 +18,11 @@ ...@@ -17,7 +18,11 @@
static inline struct fmc_device *gc_to_fmc(struct gpio_chip *gc) static inline struct fmc_device *gc_to_fmc(struct gpio_chip *gc)
{ {
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
struct device *dev = gc->dev; struct device *dev = gc->dev;
#else
struct device *dev = gc->parent;
#endif
return container_of(dev, struct fmc_device, dev); return container_of(dev, struct fmc_device, dev);
} }
...@@ -72,7 +77,11 @@ int wrn_gpio_init(struct fmc_device *fmc) ...@@ -72,7 +77,11 @@ int wrn_gpio_init(struct fmc_device *fmc)
if (!gc) if (!gc)
return -ENOMEM; return -ENOMEM;
*gc = wrn_gpio_template; *gc = wrn_gpio_template;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
gc->dev = &fmc->dev; gc->dev = &fmc->dev;
#else
gc->parent = &fmc->dev;
#endif
ret = gpiochip_add(gc); ret = gpiochip_add(gc);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment