summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-mockup.c
AgeCommit message (Collapse)AuthorFilesLines
2023-11-20gpio: mockup: initialize a managed pointer in placeBartosz Golaszewski1-2/+1
The preferred pattern for autopointers is to initialize them when they're declared unless it doesn't make sense. Move the declaration of the managed device pointer to where it's initialized. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-09-11gpio: mockup: don't access internal GPIOLIB structuresBartosz Golaszewski1-9/+30
Don't include gpiolib.h. Track the request status of lines locally instead. In order to retrieve the device name use the fact that gpio-mockup supports only a single GPIO device per platform device and call device_find_any_child(). Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-09-11gpio: mockup: simplify code by using cleanup helpersBartosz Golaszewski1-24/+21
Use lock from linux/cleanup.h and simplify locking paths. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-09-11gpio: mockup: remove unused fieldBartosz Golaszewski1-2/+0
The desc assigned to debugfs private structure is unused so remove it. Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-09-11gpio: mockup: fix kerneldocBartosz Golaszewski1-0/+2
The pull field of the line state struct is undocumented. Fix it. Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-05-17gpio: mockup: Fix mode of debugfs filesZev Weiss1-1/+1
This driver's debugfs files have had a read operation since commit 2a9e27408e12 ("gpio: mockup: rework debugfs interface"), but were still being created with write-only mode bits. Update them to indicate that the files can also be read. Signed-off-by: Zev Weiss <zev@bewilderbeest.net> Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface") Cc: stable@kernel.org # v5.1+ Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-10-24gpio: mockup: Add missing header(s)Andy Shevchenko1-0/+1
Do not imply that some of the generic headers may be always included. Instead, include explicitly what we are direct user of. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2022-09-20gpio: mockup: Fix potential resource leakage when register a chipAndy Shevchenko1-1/+3
If creation of software node fails, the locally allocated string array is left unfreed. Free it on error path. Fixes: 6fda593f3082 ("gpio: mockup: Convert to use software nodes") Cc: stable@vger.kernel.org Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2022-09-20gpio: mockup: fix NULL pointer dereference when removing debugfsBartosz Golaszewski1-1/+1
We now remove the device's debugfs entries when unbinding the driver. This now causes a NULL-pointer dereference on module exit because the platform devices are unregistered *after* the global debugfs directory has been recursively removed. Fix it by unregistering the devices first. Fixes: 303e6da99429 ("gpio: mockup: remove gpio debugfs when remove device") Cc: Wei Yongjun <weiyongjun1@huawei.com> Cc: stable@vger.kernel.org Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2022-08-28gpio: mockup: remove gpio debugfs when remove deviceWei Yongjun1-1/+8
GPIO mockup debugfs is created in gpio_mockup_probe() but forgot to remove when remove device. This patch add a devm managed callback for removing them. Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2021-11-19gpio: mockup: Switch to use kasprintf_strarray()Andy Shevchenko1-22/+1
Since we have a generic helper, switch the module to use it. No functional change intended. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Bartosz Golaszewski <brgl@bgdev.pl> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2021-10-06gpio: mockup: Convert to use software nodesAndy Shevchenko1-3/+18
The gpio-mockup driver creates the properties that are shared between platform and GPIO devices. Because of that, the properties may not be removed at the proper point of time without provoking a use-after-free as shown in the following backtrace: refcount_t: underflow; use-after-free. WARNING: CPU: 0 PID: 103 at lib/refcount.c:28 refcount_warn_saturate+0xd1/0x120 ... Call Trace: kobject_put+0xdc/0xf0 software_node_notify_remove+0xa8/0xc0 device_del+0x15a/0x3e0 That's why the driver has to manage the lifetime of the software nodes by itself. The problem originates from the old device_add_properties() API, but has been only revealed after the commit bd1e336aa853 ("driver core: platform: Remove platform_device_add_properties()"). Hence, it's used as a landmark for backporting. Fixes: bd1e336aa853 ("driver core: platform: Remove platform_device_add_properties()") Reported-by: Kent Gibson <warthog618@gmail.com> Tested-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> [Bartosz: tweaked local variable placement] Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2021-05-12gpio: mockup: Switch to use gpiochip_get_desc()Andy Shevchenko1-6/+3
Switch to use gpiochip_get_desc() helper. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-03-26gpio: mockup: Drop duplicate NULL check in gpio_mockup_unregister_pdevs()Andy Shevchenko1-7/+2
Since platform_device_unregister() is NULL-aware, we don't need to duplicate this check. Remove it and fold the rest of the code. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-10-29gpio: mockup: Allow probing from device treeVincent Whitchurch1-2/+9
Allow the mockup driver to be probed via the device tree without any module parameters, allowing it to be used to configure and test higher level drivers like the leds-gpio driver and corresponding userspace before actual hardware is available. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-09-30gpio: mockup: refactor the module init functionBartosz Golaszewski1-47/+49
Let's move the code preparing the device properties into a separate routine. This has the advantage of simplifying the error handling and makes the indentation less deep. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: use the generic 'gpio-line-names' propertyBartosz Golaszewski1-32/+38
GPIO line names are currently created by the driver from the chip label. We'll want to support custom formats for line names (for instance: to name all lines the same) for user-space tests so create them in the module init function and pass them to the driver using the standard 'gpio-line-names' property. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: pass the chip label as device propertyBartosz Golaszewski1-9/+8
While we do check the "chip-name" property in probe(), we never actually use it. Let's pass the chip label to the driver using device properties as we'll want to allow users to define their own once dynamically created chips are supported. The property is renamed to "chip-label" to not cause any confusion with the actual chip name which is of the form: "gpiochipX". If the "chip-label" property is missing, let's do what most devices in drivers/gpio/ do and use dev_name(). Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: increase the number of supported device propertiesBartosz Golaszewski1-2/+2
The driver actually supports 4 properties but we only ever set up up to three. This will change however in upcoming patches so increase the number of really (as in: the number the property array can hold) supported properties to 4. Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: remove unneeded return statementBartosz Golaszewski1-2/+0
There's a return; at the end of a void function. This is not needed so remove it. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: use pr_fmt()Bartosz Golaszewski1-4/+4
We don't need a custom logging helper. Let's use the standard pr_fmt() macro which allows us to use all pr_*() routines with custom format. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: use KBUILD_MODNAMEBartosz Golaszewski1-4/+3
Drop the definition for the driver name. Let's use KBUILD_MODNAME for the log format and use the "gpio-mockup" value directly in the only place where it's relevant: in the name of the device. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: drop unneeded includesBartosz Golaszewski1-2/+0
This module doesn't need gpio/consumer.h - it's a provider. It also doesn't use any symbols from init.h so let's remove both includes. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-09-30gpio: mockup: fix resource leak in error pathBartosz Golaszewski1-0/+2
If the module init function fails after creating the debugs directory, it's never removed. Add proper cleanup calls to avoid this resource leak. Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs") Cc: <stable@vger.kernel.org> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-05-18genirq/irq_sim: Simplify the APIBartosz Golaszewski1-11/+42
The interrupt simulator API exposes a lot of custom data structures and functions and doesn't reuse the interfaces already exposed by the irq subsystem. This patch tries to address it. We hide all the simulator-related data structures from users and instead rely on the well-known irq domain. When creating the interrupt simulator the user receives a pointer to a newly created irq_domain and can use it to create mappings for simulated interrupts. It is also possible to pass a handle to fwnode when creating the simulator domain and retrieve it using irq_find_matching_fwnode(). The irq_sim_fire() function is dropped as well. Instead we implement the irq_get/set_irqchip_state interface. We modify the two modules that use the simulator at the same time as adding these changes in order to reduce the intermediate bloat that would result when trying to migrate the drivers in separate patches. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> #for IIO Link: https://lore.kernel.org/r/20200514083901.23445-3-brgl@bgdev.pl
2020-02-20gpio: mockup: coding-style fixBartosz Golaszewski1-1/+1
The indentation is wrong in gpio_mockup_apply_pull(). This patch makes the code more readable. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20200210155059.29609-1-brgl@bgdev.pl Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-17Merge tag 'v5.5-rc6' into develLinus Walleij1-4/+7
Linux 5.5-rc6
2020-01-15gpio: mockup: sort headers alphabeticallyBartosz Golaszewski1-7/+7
For consistency and easier maintenance: sort the headers alphabetically. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20200114150253.28716-3-brgl@bgdev.pl Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-15gpio: mockup: update the license tagBartosz Golaszewski1-1/+1
The current GPL v2.0 or later SPDX tag is 'GPL-2.0-or-later' as defined at https://spdx.org/licenses/. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20200114150253.28716-2-brgl@bgdev.pl Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-01-03gpio: mockup: fix coding styleBartosz Golaszewski1-2/+2
I have missed two indentation issues in commit 64e7112ee307 ("gpio: mockup: add set_config to support pull up/down"). This commit fixes them. Fixes: 64e7112ee307 ("gpio: mockup: add set_config to support pull up/down") Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-11gpio: mockup: Fix usage of new GPIO_LINE_DIRECTIONKent Gibson1-2/+5
Restore the external behavior of gpio-mockup to what it was prior to the change to using GPIO_LINE_DIRECTION. Fixes: e42615ec233b ("gpio: Use new GPIO_LINE_DIRECTION") Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-12gpio: mockup: add set_config to support pull up/downKent Gibson1-34/+60
Add support for the pull up/down state set via gpiolib line requests to be reflected in the state of the mockup. Use case is for testing of the GPIO uAPI, specifically the pull up/down flags. Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-07gpio: Use new GPIO_LINE_DIRECTIONMatti Vaittinen1-8/+3
It's hard for occasional GPIO code reader/writer to know if values 0/1 equal to IN or OUT. Use defined GPIO_LINE_DIRECTION_IN and GPIO_LINE_DIRECTION_OUT to help them out. NOTE - for gpio-amd-fch and gpio-bd9571mwv: This commit also changes the return value for direction get to equal 1 for direction INPUT. Prior this commit these drivers might have returned some other positive value but 1 for INPUT. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Acked-by: Scott Branden <scott.branden@broadcom.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Reviewed-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-09-09gpio: mockup: add missing single_release()Wei Yongjun1-0/+1
When using single_open() for opening, single_release() should be used instead of seq_release(), otherwise there is a memory leak. Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface") Cc: stable <stable@vger.kernel.org> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-06-27gpio: mockup: no need to check return value of debugfs_create functionsGreg Kroah-Hartman1-16/+5
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this. Cc: Bamvor Jian Zhang <bamv2005@gmail.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com> Cc: linux-gpio@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [Bartosz: removed one more check for debugfs return value] Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2019-03-28gpio: mockup: use simple_read_from_buffer() in debugfs read callbackBartosz Golaszewski1-8/+2
Calling read() for a single byte read will return 2 currently. Use simple_read_from_buffer() which correctly handles all sizes. Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface") Reviewed-by: Mukesh Ojha <mojha@codeaurora.org> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-27gpio: mockup: fix debugfs readBartosz Golaszewski1-4/+6
The debugfs read callback must advance ppos or users using read() on the file descriptor will never get the EOL. This wasn't spotted before as I was using busybox cat for testing which uses sendfile() internally and only noticed it now when switched to cat from coreutils. Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface") Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: rework debugfs interfaceBartosz Golaszewski1-14/+103
Modify the way the debugfs interface works in gpio-mockup. Introduce the concept of dummy pull config which will keep the mockup lines in known state. The pull values can be modified by writing to the debugfs files corresponding to lines. Lines in input mode always report the current pull value, lines in output mode change the line value but it will revert back to the one specified by current pull when released. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: change the signature of unlocked get/set helpersBartosz Golaszewski1-11/+8
The unlocked variants only get called from places where we already have the pointer to the underlying gpio_mockup_chip structure, so take it as parameter instead of struct gpio_chip. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: change the type of 'offset' to unsigned intBartosz Golaszewski1-1/+1
This field can never be negative. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: don't create the debugfs link named after the labelBartosz Golaszewski1-5/+1
User-space tests no longer use it and we're breaking the interface anyway. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: implement get_multiple()Bartosz Golaszewski1-0/+17
We already support set_multiple(). Implement get_multiple() as well. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: add lockingBartosz Golaszewski1-7/+43
While no user reported any race condition problems with gpio-mockup, let's be on the safe side and use a mutex when performing any changes on the dummy chip structures. Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2018-11-17gpio: mockup: fix indicated directionBartosz Golaszewski1-3/+3
Commit 3edfb7bd76bd ("gpiolib: Show correct direction from the beginning") fixed an existing issue but broke libgpiod tests by changing the default direction of dummy lines to output. We don't break user-space so make gpio-mockup behave as before. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2018-10-03gpio: mockup: use device properties instead of platform_dataBartosz Golaszewski1-31/+51
Some users want to introduce device tree support to the mockup driver. Let's make it easier by switching to using generic device properties. The driver stays compatible with previous use cases and after this conversion there'll be no need to change the way probing of mockup GPIO chips works. Tested with libgpiod test suite. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2018-05-16gpio: mockup: use the SPDX identifier and remove license boilerplateBartosz Golaszewski1-6/+1
Use the SPDX license identifier for GPLv2.0 or later and remove the license boilerplate. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2018-03-27gpio: mockup: fix a potential crash when creating debugfs entriesBartosz Golaszewski1-1/+1
If we failed to create the top debugfs directory, we must not try to create the child nodes. We currently only check if gpio_mockup_dbg_dir is not NULL, but it can also contain an errno if debugfs is disabled in build options. Use IS_ERR_OR_NULL() instead. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2018-03-06gpio: mockup: Update Bamvors mail addressLinus Walleij1-2/+2
Bamvor changed his mail so let's updat his mail address everywhere. Cc: Bamvor Jian Zhang <bamv2005@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2017-12-08gpio: mockup: fix a return value checkBartosz Golaszewski1-2/+2
The return value of platform_device_register_resndata() on error is an error code converted to pointer with ERR_PTR(), not NULL. Check the return value correctly. Fixes: 8a39f597bcfd ("gpio: mockup: rework device probing") Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2017-12-03gpio: mockup: add helpers for accessing the gpio rangesBartosz Golaszewski1-4/+14
In order to avoid repeating the calculations on every access - add helpers for gpio base and ngpio components of the ranges array. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>