• Peter Rosin's avatar
    iio: pressure: mpl115: do not rely on structure field ordering · 0b95c2aa
    Peter Rosin authored
    commit 6a6e1d56 upstream.
    
    Fixes a regression triggered by a change in the layout of
    struct iio_chan_spec, but the real bug is in the driver which assumed
    a specific structure layout in the first place. Hint: the three bits were
    not OR:ed together as implied by the indentation prior to this patch,
    there was a comma between the first two, which accidentally moved the
    ..._SCALE and ..._OFFSET bits to the next structure field. That field
    was .info_mask_shared_by_type before the _available attributes was added
    by commit 51239600 ("iio:core: add a callback to allow drivers to
    provide _available attributes") and .info_mask_separate_available
    afterwards, and the regression happened.
    
    info_mask_shared_by_type is actually a better choice than the originally
    intended info_mask_separate for the ..._SCALE and ..._OFFSET bits since
    a constant is returned from mpl115_read_raw for the scale/offset. Using
    info_mask_shared_by_type also preserves the behavior from before the
    regression and is therefore less likely to cause other interesting side
    effects.
    
    The above mentioned regression causes unintended sysfs attibutes to
    show up that are not backed by code, in turn causing a NULL pointer
    defererence to happen on access.
    
    Fixes: 3017d90e ("iio: Add Freescale MPL115A2 pressure / temperature sensor driver")
    Fixes: 51239600 ("iio:core: add a callback to allow drivers to provide _available attributes")
    Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
    Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    0b95c2aa
mpl115.c 4.99 KB