Merge tag 'gpio-fixes-for-v7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fixes from Bartosz Golaszewski:
 "To no surprise, this batch was mostly driven by issues found by LLMs
  (notably: sashiko) during reviews of other changes. This is why it's
  bigger than what I normally send at this stage.

  Fixes in GPIO core:
   - fix a race in shared GPIO descriptor release path
   - fix several issues in gpio-shared-proxy: race between concurrent
     initial users, dropping votes in error paths and driving the
     default value with no votes cast
   - fix stack out-of-bounds access bugs in GPIO hog handling
   - fix a race in GPIO descriptor consumer label update
   - reset lookup flags on each hogged line
   - fix GPIO descriptor leak and fast-path cancellation in
     gpiod_get_array()
   - fix return value in of_gpiochip_instance_match() stub for
     !CONFIG_OF
   - fix potential misconfiguration of flags for hogged lines on OF
     systems
   - fix a reference leak in deferred GPIO controller setup error path

  Fixes in GPIO drivers:
   - fix interrupt handling bugs in gpio-aspeed
   - fix an interrupt leak and two UAF bugs in gpio-virtuser
   - fix a UAF bugs in gpio-sodaville, gpio-mpc8xxx and gpio-brcmstb
   - fix a sleeping-while-atomic bug in gpio-mvebu
   - reject unsupported interrupt types in gpio-mpfs
   - fix an irqchip leak in gpio-regmap helper
   - fix debounce arithmetic in gpio-rockchip
   - propagate runtime PM failures in gpio-omap
   - defer GPIO chip registration to postcore_initcall() in gpio-sa1100"

* tag 'gpio-fixes-for-v7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (26 commits)
  gpiolib: fix stack out-of-bounds access in gpiochip_add_hog()
  gpio: shared: fix a race in shared desc release path
  gpio: sodaville: fix use-after-free bug when registering the irqchip
  gpio: virtuser: fix interrupt leak and UAF
  gpio: mvebu: fix sleeping-while-atomic in mvebu_gpio_level_irq_mask()
  gpiolib: synchronize updates of descriptor labels
  gpiolib: of: return -ENOENT from of_gpio_count() stub
  gpiolib: fix fast-path cancellation in gpiod_get_array()
  gpiolib: fix GPIO descriptor leak in gpiod_get_array()
  gpio: of: fix potential misconfiguration of hogged lines
  gpio: mpfs: reject unsupported interrupt types
  gpio: keep the chip reference when deferred setup fails
  gpio: regmap: free the irqchip if adding the irq domain fails
  gpio: aspeed: Preserve the pending G7 interrupt status on control writes
  gpio: aspeed: Clear only the acked line's G4 interrupt status
  gpiolib: reset lookup flags for each hogged line
  gpio: virtuser: remove the debugfs files before freeing the line data
  gpio: mpc8xxx: Fix potential use-after-free of IRQ domain
  gpio: shared-proxy: Drop the vote when switching to input
  gpio: shared-proxy: Drive the default value when no votes are cast
  ...
This commit is contained in:
Linus Torvalds
2026-11-12 10:11:27 -08:00
18 changed files with 288 additions and 97 deletions
+18 -1
View File
@@ -1041,6 +1041,17 @@ static void aspeed_g4_reg_bit_set(struct aspeed_gpio *gpio, unsigned int offset,
void __iomem *addr = aspeed_gpio_g4_bank_reg(gpio, bank, reg);
u32 temp;
/*
* The interrupt status register is write-1-to-clear. Write only this
* line's bit so that interrupts pending on the other lines of the bank
* stay latched.
*/
if (reg == reg_irq_status) {
if (val)
iowrite32(GPIO_BIT(offset), addr);
return;
}
if (reg == reg_val)
temp = gpio->dcache[GPIO_BANK(offset)];
else
@@ -1157,7 +1168,13 @@ static void aspeed_g7_reg_bit_set(struct aspeed_gpio *gpio, unsigned int offset,
u32 write_val;
if (mask) {
write_val = (ioread32(addr) & ~(mask)) | field_prep(mask, val);
/*
* The interrupt status bit is write-1-to-clear. Keep it zero
* unless it is the field being written, so that updating any
* other field leaves a pending interrupt latched.
*/
write_val = ioread32(addr) & ~(mask | GPIO_G7_CTRL_IRQ_STS);
write_val |= field_prep(mask, val);
iowrite32(write_val, addr);
}
}
+1
View File
@@ -513,6 +513,7 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev,
out_free_domain:
irq_domain_remove(priv->irq_domain);
priv->irq_domain = NULL;
return err;
}
+15 -7
View File
@@ -319,6 +319,14 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
{}
};
static void mpc8xxx_irq_domain_remove(void *data)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = data;
if (mpc8xxx_gc->irq)
irq_domain_remove(mpc8xxx_gc->irq);
}
static int mpc8xxx_probe(struct platform_device *pdev)
{
const struct mpc8xxx_gpio_devtype *devtype = NULL;
@@ -405,6 +413,11 @@ static int mpc8xxx_probe(struct platform_device *pdev)
mpc8xxx_gc->regs + GPIO_DIR);
}
/* GPIO chip cleanup still needs the IRQ domain. */
ret = devm_add_action_or_reset(dev, mpc8xxx_irq_domain_remove, mpc8xxx_gc);
if (ret)
return ret;
ret = devm_gpiochip_add_data(dev, gc, mpc8xxx_gc);
if (ret) {
dev_err(dev,
@@ -437,7 +450,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
if (ret) {
dev_err(dev, "failed to devm_request_irq(%d), ret = %d\n",
mpc8xxx_gc->irqn, ret);
goto err;
return ret;
}
ret = devm_device_init_wakeup(dev);
@@ -445,19 +458,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "Failed to init wakeup\n");
return 0;
err:
irq_domain_remove(mpc8xxx_gc->irq);
return ret;
}
static void mpc8xxx_remove(struct platform_device *pdev)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev);
if (mpc8xxx_gc->irq) {
if (mpc8xxx_gc->irq)
irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL);
irq_domain_remove(mpc8xxx_gc->irq);
}
}
static int mpc8xxx_suspend(struct device *dev)
+2
View File
@@ -138,6 +138,8 @@ static int mpfs_gpio_irq_set_type(struct irq_data *data, unsigned int type)
case IRQ_TYPE_LEVEL_LOW:
interrupt_type = MPFS_GPIO_TYPE_INT_LEVEL_LOW;
break;
default:
return -EINVAL;
}
regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index),
+2
View File
@@ -603,6 +603,7 @@ static const struct regmap_config mvebu_gpio_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.use_raw_spinlock = true,
};
static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
@@ -610,6 +611,7 @@ static const struct regmap_config mvebu_gpio_percpu_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.use_raw_spinlock = true,
};
static const struct regmap_config mvebu_pwm_regmap_config = {
+11 -2
View File
@@ -813,8 +813,11 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
{
struct gpio_bank *bank = gpiochip_get_data(chip);
unsigned long flags;
int ret;
pm_runtime_get_sync(chip->parent);
ret = pm_runtime_resume_and_get(chip->parent);
if (ret < 0)
return ret;
raw_spin_lock_irqsave(&bank->lock, flags);
omap_enable_gpio_module(bank, offset);
@@ -1459,7 +1462,13 @@ static int omap_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, bank);
pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
ret = pm_runtime_resume_and_get(dev);
if (ret < 0) {
pm_runtime_disable(dev);
if (bank->dbck_flag)
clk_unprepare(bank->dbck);
return ret;
}
if (bank->is_mpuio)
omap_mpuio_init(bank);
+5
View File
@@ -572,6 +572,11 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
err_remove_gpiochip:
gpiochip_remove(chip);
#ifdef CONFIG_REGMAP_IRQ
if (gpio->irq_chip_data)
regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data);
#endif
err_free_bitmap_output:
bitmap_free(gpio->fixed_direction_output);
err_free_bitmap_dirmask:
+10 -5
View File
@@ -201,20 +201,25 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
{
struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
const struct rockchip_gpio_regs *reg = bank->gpio_regs;
unsigned long flags, div_reg, freq, max_debounce;
unsigned long flags, div_reg, freq;
bool div_debounce_support;
unsigned int cur_div_reg;
u64 div;
u64 div, max_debounce;
if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
div_debounce_support = true;
freq = clk_get_rate(bank->db_clk);
max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq;
if (!freq)
return -EINVAL;
div = (u64)(GENMASK(23, 0) + 1) * 2 * USEC_PER_SEC;
max_debounce = div64_u64(div, freq);
if (debounce > max_debounce)
return -EINVAL;
div = debounce * freq;
div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1;
div = (u64)debounce * freq;
div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC);
div_reg = div_reg ? div_reg - 1 : 0;
} else {
div_debounce_support = false;
}
+27 -5
View File
@@ -8,6 +8,7 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/printk.h>
#include <linux/syscore_ops.h>
#include <soc/sa1100/pwer.h>
#include <mach/hardware.h>
@@ -322,7 +323,6 @@ static const int sa1100_gpio_irqs[] __initconst = {
void __init sa1100_init_gpio(void)
{
struct sa1100_gpio_chip *sgc = &sa1100_gpio_chip;
struct gpio_chip *gc = &sgc->chip;
int i;
/* clear all GPIO edge detects */
@@ -330,10 +330,6 @@ void __init sa1100_init_gpio(void)
writel_relaxed(0, sgc->membase + R_GRER);
writel_relaxed(-1, sgc->membase + R_GEDR);
software_node_register(&sa1100_gpiochip_node);
gc->fwnode = software_node_fwnode(&sa1100_gpiochip_node);
gpiochip_add_data(gc, NULL);
sa1100_gpio_irqdomain = irq_domain_create_simple(NULL,
28, IRQ_GPIO0,
&sa1100_gpio_irqdomain_ops, sgc);
@@ -342,3 +338,29 @@ void __init sa1100_init_gpio(void)
irq_set_chained_handler_and_data(sa1100_gpio_irqs[i],
sa1100_gpio_handler, sgc);
}
static int __init sa1100_gpio_init_chip(void)
{
struct gpio_chip *gc = &sa1100_gpio_chip.chip;
int error;
error = software_node_register(&sa1100_gpiochip_node);
if (error) {
pr_err("failed to register sa1100 gpiochip software node: %d\n",
error);
return error;
}
gc->fwnode = software_node_fwnode(&sa1100_gpiochip_node);
error = gpiochip_add_data(gc, NULL);
if (error) {
pr_err("failed to add sa1100 gpiochip: %d\n", error);
gc->fwnode = NULL;
software_node_unregister(&sa1100_gpiochip_node);
return error;
}
return 0;
}
postcore_initcall(sa1100_gpio_init_chip);
+86 -12
View File
@@ -21,9 +21,37 @@ struct gpio_shared_proxy_data {
struct gpio_chip gc;
struct gpio_shared_desc *shared_desc;
struct device *dev;
bool configured;
bool voted_change;
};
/*
* A proxy may (re)initialize the line - set its direction and reset the
* default value and the vote tally - only while no other proxy has set the
* direction or voted for a value. Requesting the line is not enough: consumers
* may request concurrently, so counting requests lets every one of them
* conclude that it is not first.
*/
static bool gpio_shared_proxy_may_init(struct gpio_shared_proxy_data *proxy)
{
unsigned int cfgcnt = proxy->shared_desc->cfgcnt;
lockdep_assert_held(&proxy->shared_desc->mutex);
return !cfgcnt || (cfgcnt == 1 && proxy->configured);
}
static void gpio_shared_proxy_mark_configured(struct gpio_shared_proxy_data *proxy)
{
lockdep_assert_held(&proxy->shared_desc->mutex);
if (proxy->configured)
return;
proxy->configured = true;
proxy->shared_desc->cfgcnt++;
}
static int
gpio_shared_proxy_set_unlocked(struct gpio_shared_proxy_data *proxy, int value)
{
@@ -57,9 +85,16 @@ gpio_shared_proxy_set_unlocked(struct gpio_shared_proxy_data *proxy, int value)
}
/* Desired value is the default. */
if (!proxy->voted_change)
/* We didn't vote for change previously, nothing to do. */
if (!proxy->voted_change) {
/*
* With no votes outstanding the line should be at the
* default, but a GPIOD_ASIS line may have been left at the
* opposite value. Drive it there.
*/
if (!shared_desc->votecnt)
ret = gpiod_set_value_cansleep(desc, shared_desc->def_val);
goto out;
}
/* We previously voted for change. */
if (shared_desc->votecnt == 1) {
@@ -110,13 +145,22 @@ static void gpio_shared_proxy_free(struct gpio_chip *gc, unsigned int offset)
if (proxy->voted_change) {
ret = gpio_shared_proxy_set_unlocked(proxy, shared_desc->def_val);
if (ret)
if (ret) {
dev_err(proxy->dev,
"Failed to unset the shared GPIO value on release: %d\n", ret);
/* The consumer is going away regardless, drop its vote */
shared_desc->votecnt--;
proxy->voted_change = false;
}
}
proxy->shared_desc->usecnt--;
if (proxy->configured) {
proxy->configured = false;
shared_desc->cfgcnt--;
}
dev_dbg(proxy->dev, "Shared GPIO freed, number of users: %u\n",
proxy->shared_desc->usecnt);
}
@@ -131,7 +175,7 @@ static int gpio_shared_proxy_set_config(struct gpio_chip *gc,
guard(mutex)(&shared_desc->mutex);
if (shared_desc->usecnt > 1) {
if (!gpio_shared_proxy_may_init(proxy)) {
if (shared_desc->cfg != cfg) {
dev_dbg(proxy->dev,
"Shared GPIO's configuration already set, accepting changes but users may conflict!!\n");
@@ -155,15 +199,24 @@ static int gpio_shared_proxy_direction_input(struct gpio_chip *gc,
struct gpio_shared_proxy_data *proxy = gpiochip_get_data(gc);
struct gpio_shared_desc *shared_desc = proxy->shared_desc;
struct gpio_desc *desc = shared_desc->desc;
int dir;
int ret, dir;
guard(mutex)(&shared_desc->mutex);
if (shared_desc->usecnt == 1) {
if (gpio_shared_proxy_may_init(proxy)) {
dev_dbg(proxy->dev,
"Only one user of this shared GPIO, allowing to set direction to input\n");
"No other user configured this shared GPIO, allowing to set direction to input\n");
return gpiod_direction_input(desc);
ret = gpiod_direction_input(desc);
if (ret)
return ret;
/* An input carries no value, drop any vote this proxy cast */
shared_desc->votecnt = 0;
proxy->voted_change = false;
gpio_shared_proxy_mark_configured(proxy);
return 0;
}
dir = gpiod_get_direction(desc);
@@ -176,6 +229,8 @@ static int gpio_shared_proxy_direction_input(struct gpio_chip *gc,
return -EPERM;
}
gpio_shared_proxy_mark_configured(proxy);
return 0;
}
@@ -189,18 +244,20 @@ static int gpio_shared_proxy_direction_output(struct gpio_chip *gc,
guard(mutex)(&shared_desc->mutex);
if (shared_desc->usecnt == 1) {
if (gpio_shared_proxy_may_init(proxy)) {
dev_dbg(proxy->dev,
"Only one user of this shared GPIO, allowing to set direction to output with value '%s'\n",
"No other user configured this shared GPIO, allowing to set direction to output with value '%s'\n",
str_high_low(value));
ret = gpiod_direction_output(desc, value);
if (ret)
return ret;
/* Only this proxy can have voted, so the tally is ours to reset */
shared_desc->def_val = value;
shared_desc->votecnt = 0;
proxy->voted_change = false;
gpio_shared_proxy_mark_configured(proxy);
return 0;
}
@@ -215,7 +272,13 @@ static int gpio_shared_proxy_direction_output(struct gpio_chip *gc,
return -EPERM;
}
return gpio_shared_proxy_set_unlocked(proxy, value);
ret = gpio_shared_proxy_set_unlocked(proxy, value);
if (ret)
return ret;
gpio_shared_proxy_mark_configured(proxy);
return 0;
}
static int gpio_shared_proxy_get_cansleep(struct gpio_chip *gc,
@@ -230,10 +293,21 @@ static int gpio_shared_proxy_set_cansleep(struct gpio_chip *gc,
unsigned int offset, int value)
{
struct gpio_shared_proxy_data *proxy = gpiochip_get_data(gc);
int ret;
guard(mutex)(&proxy->shared_desc->mutex);
return gpio_shared_proxy_set_unlocked(proxy, value);
/*
* A GPIOD_ASIS consumer may vote without ever setting the direction;
* count it as configured so a later user can't reset its vote.
*/
ret = gpio_shared_proxy_set_unlocked(proxy, value);
if (ret)
return ret;
gpio_shared_proxy_mark_configured(proxy);
return 0;
}
static int gpio_shared_proxy_get_direction(struct gpio_chip *gc,
+6 -3
View File
@@ -166,9 +166,12 @@ static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd,
ct->chip.irq_eoi = irq_gc_eoi;
ct->chip.irq_set_type = sdv_gpio_pub_set_type;
irq_setup_generic_chip(sd->gc, IRQ_MSK(SDV_NUM_PUB_GPIOS),
IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST,
IRQ_LEVEL | IRQ_NOPROBE);
ret = devm_irq_setup_generic_chip(&pdev->dev, sd->gc,
IRQ_MSK(SDV_NUM_PUB_GPIOS),
IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST,
IRQ_LEVEL | IRQ_NOPROBE);
if (ret)
return ret;
sd->id = irq_domain_create_legacy(dev_fwnode(&pdev->dev), SDV_NUM_PUB_GPIOS, sd->irq_base,
0, &irq_domain_sdv_ops, sd);
+58 -27
View File
@@ -55,9 +55,9 @@ struct gpio_virtuser_line_array_data {
struct gpio_virtuser_line_data {
struct gpio_virtuser_attr_data ad;
char consumer[GPIO_VIRTUSER_NAME_BUF_LEN];
struct mutex consumer_lock;
struct mutex lock;
unsigned int debounce;
atomic_t irq;
int irq;
atomic_t irq_count;
};
@@ -607,7 +607,7 @@ static ssize_t gpio_virtuser_consumer_read(struct file *file,
memset(buf, 0x0, sizeof(buf));
scoped_guard(mutex, &data->consumer_lock)
scoped_guard(mutex, &data->lock)
ret = snprintf(buf, sizeof(buf), "%s\n", data->consumer);
return simple_read_from_buffer(user_buf, size, ppos, buf, ret);
@@ -635,7 +635,7 @@ static ssize_t gpio_virtuser_consumer_write(struct file *file,
if (ret)
return ret;
scoped_guard(mutex, &data->consumer_lock)
scoped_guard(mutex, &data->lock)
strscpy(data->consumer, buf, sizeof(data->consumer));
return count;
@@ -675,7 +675,12 @@ static int gpio_virtuser_interrupts_set(void *data, u64 val)
if (val > 1)
return -EINVAL;
guard(mutex)(&ld->lock);
if (val) {
if (ld->irq >= 0)
return -EBUSY;
irq = gpiod_to_irq(ld->ad.desc);
if (irq < 0)
return irq;
@@ -689,11 +694,13 @@ static int gpio_virtuser_interrupts_set(void *data, u64 val)
if (ret)
return ret;
atomic_set(&ld->irq, irq);
ld->irq = irq;
} else {
irq = atomic_xchg(&ld->irq, 0);
if (irq)
free_irq(irq, ld);
if (ld->irq < 0)
return -EBUSY;
free_irq(ld->irq, ld);
ld->irq = -1;
}
return 0;
@@ -793,6 +800,14 @@ static int gpio_virtuser_dbgfs_init_line_array_attrs(struct device *dev,
data->ad.dbgfs_dir, data);
}
static void gpio_virtuser_free_irq(void *data)
{
struct gpio_virtuser_line_data *ld = data;
if (ld->irq >= 0)
free_irq(ld->irq, ld);
}
static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev,
struct gpio_desc *desc,
const char *id,
@@ -809,14 +824,18 @@ static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev,
data->ad.desc = desc;
strscpy(data->consumer, id);
atomic_set(&data->irq, 0);
data->irq = -1;
atomic_set(&data->irq_count, 0);
ret = devm_add_action_or_reset(dev, gpio_virtuser_free_irq, data);
if (ret)
return ret;
name = devm_kasprintf(dev, GFP_KERNEL, "gpiod:%s:%u", id, index);
if (!name)
return -ENOMEM;
ret = devm_mutex_init(dev, &data->consumer_lock);
ret = devm_mutex_init(dev, &data->lock);
if (ret)
return ret;
@@ -927,38 +946,50 @@ static int gpio_virtuser_probe(struct platform_device *pdev)
"Failed to get the IDs of GPIOs to request\n");
dbgfs_entry = debugfs_create_dir(dev_name(dev), gpio_virtuser_dbg_root);
ret = devm_add_action_or_reset(dev, gpio_virtuser_debugfs_remove,
dbgfs_entry);
if (ret)
return ret;
for (i = 0; i < num_ids; i++) {
descs = devm_gpiod_get_array(dev, ids[i], GPIOD_ASIS);
if (IS_ERR(descs))
return dev_err_probe(dev, PTR_ERR(descs),
"Failed to request the '%s' GPIOs\n",
ids[i]);
if (IS_ERR(descs)) {
ret = dev_err_probe(dev, PTR_ERR(descs),
"Failed to request the '%s' GPIOs\n",
ids[i]);
goto err_remove_debugfs;
}
ret = gpio_virtuser_dbgfs_init_line_array_attrs(dev, descs,
ids[i],
dbgfs_entry);
if (ret)
return dev_err_probe(dev, ret,
"Failed to setup the debugfs array interface for the '%s' GPIOs\n",
ids[i]);
if (ret) {
dev_err_probe(dev, ret,
"Failed to setup the debugfs array interface for the '%s' GPIOs\n",
ids[i]);
goto err_remove_debugfs;
}
for (j = 0; j < descs->ndescs; j++) {
ret = gpio_virtuser_dbgfs_init_line_attrs(dev,
descs->desc[j], ids[i],
j, dbgfs_entry);
if (ret)
return dev_err_probe(dev, ret,
"Failed to setup the debugfs line interface for the '%s' GPIOs\n",
ids[i]);
if (ret) {
dev_err_probe(dev, ret,
"Failed to setup the debugfs line interface for the '%s' GPIOs\n",
ids[i]);
goto err_remove_debugfs;
}
}
}
return 0;
/*
* The debugfs files point to the devres-managed line data allocated
* above. Register the removal last so that it runs first on unbind,
* before any of that data is released.
*/
return devm_add_action_or_reset(dev, gpio_virtuser_debugfs_remove,
dbgfs_entry);
err_remove_debugfs:
debugfs_remove_recursive(dbgfs_entry);
return ret;
}
static const struct of_device_id gpio_virtuser_of_match[] = {
+1 -1
View File
@@ -725,7 +725,7 @@ int of_gpiochip_get_lflags(struct gpio_chip *chip,
struct fwnode_reference_args *gpiospec,
unsigned long *lflags)
{
enum of_gpio_flags xlate_flags;
enum of_gpio_flags xlate_flags = 0;
struct of_phandle_args args;
struct gpio_desc *desc;
+1 -1
View File
@@ -46,7 +46,7 @@ static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,
static inline int of_gpio_count(const struct fwnode_handle *fwnode,
const char *con_id)
{
return 0;
return -ENOENT;
}
static inline int of_gpiochip_get_lflags(struct gpio_chip *chip,
struct fwnode_reference_args *gpiospec,
+3 -3
View File
@@ -635,20 +635,20 @@ static void gpio_shared_release(struct kref *kref)
container_of(kref, struct gpio_shared_entry, ref);
struct gpio_shared_desc *shared_desc;
guard(mutex)(&entry->lock);
shared_desc = entry->shared_desc;
gpio_device_put(shared_desc->desc->gdev);
mutex_destroy(&shared_desc->mutex);
kfree(shared_desc);
entry->shared_desc = NULL;
mutex_unlock(&entry->lock);
}
static void gpiod_shared_put(void *data)
{
struct gpio_shared_entry *entry = data;
kref_put(&entry->ref, gpio_shared_release);
kref_put_mutex(&entry->ref, gpio_shared_release, &entry->lock);
}
static struct gpio_shared_desc *
+1
View File
@@ -41,6 +41,7 @@ struct gpio_shared_desc {
struct gpio_desc *desc;
unsigned long cfg;
unsigned int usecnt;
unsigned int cfgcnt;
unsigned int votecnt;
int def_val;
struct mutex mutex; /* serializes all proxy operations on this descriptor */
+39 -30
View File
@@ -154,9 +154,12 @@ static int desc_set_label(struct gpio_desc *desc, const char *label)
memcpy(new->str, label, len);
}
old = rcu_replace_pointer(desc->label, new, 1);
if (old)
call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);
scoped_guard(spinlock, &desc->gdev->desc_lock) {
old = rcu_replace_pointer(desc->label, new,
lockdep_is_held(&desc->gdev->desc_lock));
if (old)
call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);
}
return 0;
}
@@ -924,7 +927,8 @@ static const struct device_type gpio_dev_type = {
/*
* An initial reference count has been held in gpiochip_add_data_with_key().
* The caller should drop the reference via gpio_device_put() on errors.
* A caller that tears the chip down on errors must drop the reference via
* gpio_device_put().
*/
static int gpiochip_setup_dev(struct gpio_chip *gc)
{
@@ -975,7 +979,6 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
*/
u32 cells = 2;
lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
dflags = GPIOD_ASIS;
name = NULL;
@@ -986,6 +989,8 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells);
if (ret && is_of_node(fwnode))
return ret;
if (cells < 1 || cells > NR_FWNODE_REFERENCE_ARGS)
return -EINVAL;
if (argc % cells)
return -EINVAL;
@@ -1014,6 +1019,8 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
fwnode_property_read_string(fwnode, "line-name", &name);
for (unsigned int i = 0; i < num_hogs; i++) {
lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
if (is_of_node(fwnode)) {
/*
* OF-nodes need some additional special handling for
@@ -1039,9 +1046,10 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
} else {
/*
* GPIO_ACTIVE_LOW is currently the only lookup flag
* supported for non-OF firmware nodes.
* supported for non-OF firmware nodes and it must live
* in the second cell.
*/
if (gpios[i * cells + 1])
if (cells > 1 && gpios[i * cells + 1])
lflags |= GPIO_ACTIVE_LOW;
}
@@ -1099,12 +1107,16 @@ static void gpiochip_setup_devs(void)
continue;
}
/*
* The reference taken in gpiochip_add_data_with_key() is
* dropped by gpiochip_remove(): this chip is still registered
* and its driver has not been told about the failure, so the
* reference must be kept here.
*/
ret = gpiochip_setup_dev(gc);
if (ret) {
gpio_device_put(gdev);
if (ret)
dev_err(&gdev->dev,
"Failed to initialize gpio device (%d)\n", ret);
}
}
}
@@ -1201,6 +1213,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
goto err_free_ida;
rcu_assign_pointer(gdev->chip, gc);
spin_lock_init(&gdev->desc_lock);
ret = init_srcu_struct(&gdev->desc_srcu);
if (ret)
goto err_cleanup_gdev_srcu;
@@ -5243,21 +5257,21 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
if (!descs)
return ERR_PTR(-ENOMEM);
for (descs->ndescs = 0; descs->ndescs < count; descs->ndescs++) {
desc = gpiod_get_index(dev, con_id, descs->ndescs, flags);
for (int i = 0; i < count; i++) {
desc = gpiod_get_index(dev, con_id, i, flags);
if (IS_ERR(desc)) {
gpiod_put_array(descs);
return ERR_CAST(desc);
}
descs->desc[descs->ndescs] = desc;
descs->desc[descs->ndescs++] = desc;
gdev = gpiod_to_gpio_device(desc);
/*
* If pin hardware number of array member 0 is also 0, select
* its chip as a candidate for fast bitmap processing path.
*/
if (descs->ndescs == 0 && gpiod_hwgpio(desc) == 0) {
if (i == 0 && gpiod_hwgpio(desc) == 0) {
struct gpio_descs *array;
bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ?
@@ -5282,10 +5296,8 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
array_info->desc = descs->desc;
array_info->size = count;
array_info->gdev = gdev;
bitmap_set(array_info->get_mask, descs->ndescs,
count - descs->ndescs);
bitmap_set(array_info->set_mask, descs->ndescs,
count - descs->ndescs);
bitmap_set(array_info->get_mask, 0, count);
bitmap_set(array_info->set_mask, 0, count);
descs->info = array_info;
}
@@ -5295,38 +5307,35 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
/* Unmark array members which don't belong to the 'fast' chip */
if (array_info->gdev != gdev) {
__clear_bit(descs->ndescs, array_info->get_mask);
__clear_bit(descs->ndescs, array_info->set_mask);
__clear_bit(i, array_info->get_mask);
__clear_bit(i, array_info->set_mask);
}
/*
* Detect array members which belong to the 'fast' chip
* but their pins are not in hardware order.
*/
else if (gpiod_hwgpio(desc) != descs->ndescs) {
else if (gpiod_hwgpio(desc) != i) {
/*
* Don't use fast path if all array members processed so
* far belong to the same chip as this one but its pin
* hardware number is different from its array index.
*/
if (bitmap_full(array_info->get_mask, descs->ndescs)) {
if (bitmap_full(array_info->get_mask, i)) {
descs->info = NULL;
array_info = NULL;
} else {
__clear_bit(descs->ndescs,
array_info->get_mask);
__clear_bit(descs->ndescs,
array_info->set_mask);
__clear_bit(i, array_info->get_mask);
__clear_bit(i, array_info->set_mask);
}
} else {
dflags = READ_ONCE(desc->flags);
/* Exclude open drain or open source from fast output */
if (test_bit(GPIOD_FLAG_OPEN_DRAIN, &dflags) ||
test_bit(GPIOD_FLAG_OPEN_SOURCE, &dflags))
__clear_bit(descs->ndescs,
array_info->set_mask);
__clear_bit(i, array_info->set_mask);
/* Identify 'fast' pins which require invertion */
if (gpiod_is_active_low(desc))
__set_bit(descs->ndescs,
array_info->invert_mask);
__set_bit(i, array_info->invert_mask);
}
}
if (array_info)
+2
View File
@@ -37,6 +37,7 @@ struct fwnode_handle;
* @valid_mask: If not %NULL, holds bitmask of GPIOs which are valid to be
* used from the chip.
* @desc_srcu: ensures consistent state of GPIO descriptors exposed to users
* @desc_lock: synchronizes the updates to descriptor labels
* @ngpio: the number of GPIO lines on this GPIO device, equal to the size
* of the @descs array.
* @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep
@@ -71,6 +72,7 @@ struct gpio_device {
struct gpio_desc *descs;
unsigned long *valid_mask;
struct srcu_struct desc_srcu;
spinlock_t desc_lock;
unsigned int base;
u16 ngpio;
bool can_sleep;