summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-mockup.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* gpio: mockup: Add missing header(s)Andy Shevchenko2022-10-241-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>
* gpio: mockup: Fix potential resource leakage when register a chipAndy Shevchenko2022-09-201-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>
* gpio: mockup: fix NULL pointer dereference when removing debugfsBartosz Golaszewski2022-09-201-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>
* gpio: mockup: remove gpio debugfs when remove deviceWei Yongjun2022-08-281-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>
* gpio: mockup: Switch to use kasprintf_strarray()Andy Shevchenko2021-11-191-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>
* gpio: mockup: Convert to use software nodesAndy Shevchenko2021-10-061-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>
* gpio: mockup: Switch to use gpiochip_get_desc()Andy Shevchenko2021-05-121-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>
* gpio: mockup: Drop duplicate NULL check in gpio_mockup_unregister_pdevs()Andy Shevchenko2021-03-261-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>
* gpio: mockup: Allow probing from device treeVincent Whitchurch2020-10-291-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>
* gpio: mockup: refactor the module init functionBartosz Golaszewski2020-09-301-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>
* gpio: mockup: use the generic 'gpio-line-names' propertyBartosz Golaszewski2020-09-301-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>
* gpio: mockup: pass the chip label as device propertyBartosz Golaszewski2020-09-301-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>
* gpio: mockup: increase the number of supported device propertiesBartosz Golaszewski2020-09-301-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>
* gpio: mockup: remove unneeded return statementBartosz Golaszewski2020-09-301-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>
* gpio: mockup: use pr_fmt()Bartosz Golaszewski2020-09-301-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>
* gpio: mockup: use KBUILD_MODNAMEBartosz Golaszewski2020-09-301-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>
* gpio: mockup: drop unneeded includesBartosz Golaszewski2020-09-301-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>
* gpio: mockup: fix resource leak in error pathBartosz Golaszewski2020-09-301-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>
* genirq/irq_sim: Simplify the APIBartosz Golaszewski2020-05-181-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
* gpio: mockup: coding-style fixBartosz Golaszewski2020-02-201-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>
* Merge tag 'v5.5-rc6' into develLinus Walleij2020-01-171-4/+7
|\ | | | | | | Linux 5.5-rc6
| * gpio: mockup: fix coding styleBartosz Golaszewski2020-01-031-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>
| * gpio: mockup: Fix usage of new GPIO_LINE_DIRECTIONKent Gibson2019-12-111-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>
* | gpio: mockup: sort headers alphabeticallyBartosz Golaszewski2020-01-151-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>
* | gpio: mockup: update the license tagBartosz Golaszewski2020-01-151-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>
* gpio: mockup: add set_config to support pull up/downKent Gibson2019-11-121-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>
* gpio: Use new GPIO_LINE_DIRECTIONMatti Vaittinen2019-11-071-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>
* gpio: mockup: add missing single_release()Wei Yongjun2019-09-091-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>
* gpio: mockup: no need to check return value of debugfs_create functionsGreg Kroah-Hartman2019-06-271-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>
* gpio: mockup: use simple_read_from_buffer() in debugfs read callbackBartosz Golaszewski2019-03-281-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>
* gpio: mockup: fix debugfs readBartosz Golaszewski2019-03-271-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>
* gpio: mockup: rework debugfs interfaceBartosz Golaszewski2019-02-191-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>
* gpio: mockup: change the signature of unlocked get/set helpersBartosz Golaszewski2019-02-191-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>
* gpio: mockup: change the type of 'offset' to unsigned intBartosz Golaszewski2019-02-191-1/+1
| | | | | | This field can never be negative. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
* gpio: mockup: don't create the debugfs link named after the labelBartosz Golaszewski2019-02-191-5/+1
| | | | | | | User-space tests no longer use it and we're breaking the interface anyway. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
* gpio: mockup: implement get_multiple()Bartosz Golaszewski2019-02-191-0/+17
| | | | | | We already support set_multiple(). Implement get_multiple() as well. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
* gpio: mockup: add lockingBartosz Golaszewski2019-02-191-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>
* gpio: mockup: fix indicated directionBartosz Golaszewski2018-11-161-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>
* gpio: mockup: use device properties instead of platform_dataBartosz Golaszewski2018-10-031-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>
* gpio: mockup: use the SPDX identifier and remove license boilerplateBartosz Golaszewski2018-05-161-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>
* gpio: mockup: fix a potential crash when creating debugfs entriesBartosz Golaszewski2018-03-271-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>
* gpio: mockup: Update Bamvors mail addressLinus Walleij2018-03-061-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>
* gpio: mockup: fix a return value checkBartosz Golaszewski2017-12-081-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>
* gpio: mockup: add helpers for accessing the gpio rangesBartosz Golaszewski2017-12-021-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>
* gpio: mockup: rename gpio_mockup_params_nr to gpio_mockup_num_rangesBartosz Golaszewski2017-12-021-6/+6
| | | | | | | | This variable holds the number of mockup GPIO ranges so rename it accordingly. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: mockup: modify the return value check for devm_irq_sim_init()Bartosz Golaszewski2017-12-021-1/+1
| | | | | | | | | | As discussed with Marc Zyngier: irq_sim_init() and its devres variant should return the base of the allocated interrupt range on success rather than 0. This will be modified later - first, change the way users handle the return value of these routines. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: mockup: implement gpio_mockup_set_multiple()Bartosz Golaszewski2017-12-021-0/+11
| | | | | | | | Implement the set_multiple() callback and register it with the gpiolib framework. This is only meant to also test the internal kernel API. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: mockup: tweak line breaksBartosz Golaszewski2017-12-021-4/+4
| | | | | | | | Minor readability tweak: prefer breaking the lines in a way where the second part is longer than the first. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: mockup: verify that ngpio > 0Bartosz Golaszewski2017-12-021-0/+9
| | | | | | | | Improve the module params sanitization: bail out from init if the user tries to pass a non-positive number of GPIO lines for any mockup chip. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: mockup: fix debugfs handlingBartosz Golaszewski2017-12-021-5/+5
| | | | | | | | | | | | The debugfs routines returning pointers can return NULL or error codes embedded with ERR_PTR(). Check the return values with IS_ERR_OR_NULL(). While we're at it: make the error message more specific so it's not confused with the one emitted when the top-level gpio-mockup debugfs directory creation fails. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>