• Kent Gibson's avatar
    gpiolib: cdev: Disallow reconfiguration without direction (uAPI v1) · 9919cce6
    Kent Gibson authored
    linehandle_set_config() behaves badly when direction is not set.
    The configuration validation is borrowed from linehandle_create(), where,
    to verify the intent of the user, the direction must be set to in order
    to effect a change to the electrical configuration of a line. But, when
    applied to reconfiguration, that validation does not allow for the unset
    direction case, making it possible to clear flags set previously without
    specifying the line direction.
    
    Adding to the inconsistency, those changes are not immediately applied by
    linehandle_set_config(), but will take effect when the line value is next
    get or set.
    
    For example, by requesting a configuration with no flags set, an output
    line with GPIOHANDLE_REQUEST_ACTIVE_LOW and GPIOHANDLE_REQUEST_OPEN_DRAIN
    requested could have those flags cleared, inverting the sense of the line
    and changing the line drive to push-pull on the next line value set.
    
    Ensure the intent of the user by disallowing configurations which do not
    have direction set, returning an error to userspace to indicate that the
    configuration is invalid.
    
    And, for clarity, use lflags, a local copy of gcnf.flags, throughout when
    dealing with the requested flags, rather than a mixture of both.
    
    Fixes: e588bb1e
    
     ("gpio: add new SET_CONFIG ioctl() to gpio chardev")
    Signed-off-by: default avatarKent Gibson <warthog618@gmail.com>
    Link: https://lore.kernel.org/r/20240626052925.174272-2-warthog618@gmail.com
    
    Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
    9919cce6
gpiolib-cdev.c 72.8 KB