From: Sasha Levin Date: Wed, 30 Nov 2022 02:18:37 +0000 (-0500) Subject: Fixes for 4.19 X-Git-Tag: v5.10.157~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=18eaf13d2f666fc71adaae88b1af72a287434d0d;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.19 Signed-off-by: Sasha Levin --- diff --git a/queue-4.19/ceph-avoid-putting-the-realm-twice-when-decoding-sna.patch b/queue-4.19/ceph-avoid-putting-the-realm-twice-when-decoding-sna.patch new file mode 100644 index 00000000000..5a11cc10968 --- /dev/null +++ b/queue-4.19/ceph-avoid-putting-the-realm-twice-when-decoding-sna.patch @@ -0,0 +1,48 @@ +From 900cbf938ced6cb58fe20abf535c5c7a07e2fca4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 9 Nov 2022 11:00:39 +0800 +Subject: ceph: avoid putting the realm twice when decoding snaps fails + +From: Xiubo Li + +[ Upstream commit 51884d153f7ec85e18d607b2467820a90e0f4359 ] + +When decoding the snaps fails it maybe leaving the 'first_realm' +and 'realm' pointing to the same snaprealm memory. And then it'll +put it twice and could cause random use-after-free, BUG_ON, etc +issues. + +Cc: stable@vger.kernel.org +Link: https://tracker.ceph.com/issues/57686 +Signed-off-by: Xiubo Li +Reviewed-by: Ilya Dryomov +Signed-off-by: Ilya Dryomov +Signed-off-by: Sasha Levin +--- + fs/ceph/snap.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c +index 642040beef91..a5ef8275440d 100644 +--- a/fs/ceph/snap.c ++++ b/fs/ceph/snap.c +@@ -671,7 +671,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, + struct ceph_mds_snap_realm *ri; /* encoded */ + __le64 *snaps; /* encoded */ + __le64 *prior_parent_snaps; /* encoded */ +- struct ceph_snap_realm *realm = NULL; ++ struct ceph_snap_realm *realm; + struct ceph_snap_realm *first_realm = NULL; + struct ceph_snap_realm *realm_to_rebuild = NULL; + int rebuild_snapcs; +@@ -680,6 +680,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, + + dout("update_snap_trace deletion=%d\n", deletion); + more: ++ realm = NULL; + rebuild_snapcs = 0; + ceph_decode_need(&p, e, sizeof(*ri), bad); + ri = p; +-- +2.35.1 + diff --git a/queue-4.19/ceph-do-not-update-snapshot-context-when-there-is-no.patch b/queue-4.19/ceph-do-not-update-snapshot-context-when-there-is-no.patch new file mode 100644 index 00000000000..3aff88d1d70 --- /dev/null +++ b/queue-4.19/ceph-do-not-update-snapshot-context-when-there-is-no.patch @@ -0,0 +1,127 @@ +From 9fc205dccc5223ef88f13dd644ceac7321736829 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 19 Feb 2022 14:28:33 +0800 +Subject: ceph: do not update snapshot context when there is no new snapshot + +From: Xiubo Li + +[ Upstream commit 2e586641c950e7f3e7e008404bd783a466b9b590 ] + +We will only track the uppest parent snapshot realm from which we +need to rebuild the snapshot contexts _downward_ in hierarchy. For +all the others having no new snapshot we will do nothing. + +This fix will avoid calling ceph_queue_cap_snap() on some inodes +inappropriately. For example, with the code in mainline, suppose there +are 2 directory hierarchies (with 6 directories total), like this: + +/dir_X1/dir_X2/dir_X3/ +/dir_Y1/dir_Y2/dir_Y3/ + +Firstly, make a snapshot under /dir_X1/dir_X2/.snap/snap_X2, then make a +root snapshot under /.snap/root_snap. Every time we make snapshots under +/dir_Y1/..., the kclient will always try to rebuild the snap context for +snap_X2 realm and finally will always try to queue cap snaps for dir_Y2 +and dir_Y3, which makes no sense. + +That's because the snap_X2's seq is 2 and root_snap's seq is 3. So when +creating a new snapshot under /dir_Y1/... the new seq will be 4, and +the mds will send the kclient a snapshot backtrace in _downward_ +order: seqs 4, 3. + +When ceph_update_snap_trace() is called, it will always rebuild the from +the last realm, that's the root_snap. So later when rebuilding the snap +context, the current logic will always cause it to rebuild the snap_X2 +realm and then try to queue cap snaps for all the inodes related in that +realm, even though it's not necessary. + +This is accompanied by a lot of these sorts of dout messages: + + "ceph: queue_cap_snap 00000000a42b796b nothing dirty|writing" + +Fix the logic to avoid this situation. + +Also, the 'invalidate' word is not precise here. In actuality, it will +cause a rebuild of the existing snapshot contexts or just build +non-existent ones. Rename it to 'rebuild_snapcs'. + +URL: https://tracker.ceph.com/issues/44100 +Signed-off-by: Xiubo Li +Reviewed-by: Jeff Layton +Signed-off-by: Ilya Dryomov +Stable-dep-of: 51884d153f7e ("ceph: avoid putting the realm twice when decoding snaps fails") +Signed-off-by: Sasha Levin +--- + fs/ceph/snap.c | 28 +++++++++++++++++++--------- + 1 file changed, 19 insertions(+), 9 deletions(-) + +diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c +index 5cf7b5f4db94..642040beef91 100644 +--- a/fs/ceph/snap.c ++++ b/fs/ceph/snap.c +@@ -673,12 +673,14 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, + __le64 *prior_parent_snaps; /* encoded */ + struct ceph_snap_realm *realm = NULL; + struct ceph_snap_realm *first_realm = NULL; +- int invalidate = 0; ++ struct ceph_snap_realm *realm_to_rebuild = NULL; ++ int rebuild_snapcs; + int err = -ENOMEM; + LIST_HEAD(dirty_realms); + + dout("update_snap_trace deletion=%d\n", deletion); + more: ++ rebuild_snapcs = 0; + ceph_decode_need(&p, e, sizeof(*ri), bad); + ri = p; + p += sizeof(*ri); +@@ -702,7 +704,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, + err = adjust_snap_realm_parent(mdsc, realm, le64_to_cpu(ri->parent)); + if (err < 0) + goto fail; +- invalidate += err; ++ rebuild_snapcs += err; + + if (le64_to_cpu(ri->seq) > realm->seq) { + dout("update_snap_trace updating %llx %p %lld -> %lld\n", +@@ -727,22 +729,30 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, + if (realm->seq > mdsc->last_snap_seq) + mdsc->last_snap_seq = realm->seq; + +- invalidate = 1; ++ rebuild_snapcs = 1; + } else if (!realm->cached_context) { + dout("update_snap_trace %llx %p seq %lld new\n", + realm->ino, realm, realm->seq); +- invalidate = 1; ++ rebuild_snapcs = 1; + } else { + dout("update_snap_trace %llx %p seq %lld unchanged\n", + realm->ino, realm, realm->seq); + } + +- dout("done with %llx %p, invalidated=%d, %p %p\n", realm->ino, +- realm, invalidate, p, e); ++ dout("done with %llx %p, rebuild_snapcs=%d, %p %p\n", realm->ino, ++ realm, rebuild_snapcs, p, e); + +- /* invalidate when we reach the _end_ (root) of the trace */ +- if (invalidate && p >= e) +- rebuild_snap_realms(realm, &dirty_realms); ++ /* ++ * this will always track the uppest parent realm from which ++ * we need to rebuild the snapshot contexts _downward_ in ++ * hierarchy. ++ */ ++ if (rebuild_snapcs) ++ realm_to_rebuild = realm; ++ ++ /* rebuild_snapcs when we reach the _end_ (root) of the trace */ ++ if (realm_to_rebuild && p >= e) ++ rebuild_snap_realms(realm_to_rebuild, &dirty_realms); + + if (!first_realm) + first_realm = realm; +-- +2.35.1 + diff --git a/queue-4.19/driver-core-add-device-probe-log-helper.patch b/queue-4.19/driver-core-add-device-probe-log-helper.patch new file mode 100644 index 00000000000..8789f66040f --- /dev/null +++ b/queue-4.19/driver-core-add-device-probe-log-helper.patch @@ -0,0 +1,105 @@ +From 92d6c1e7725ebaa575fa109605c8379256a7c12c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 13 Jul 2020 16:43:21 +0200 +Subject: driver core: add device probe log helper + +From: Andrzej Hajda + +[ Upstream commit a787e5400a1ceeb0ef92d71ec43aeb35b1fa1334 ] + +During probe every time driver gets resource it should usually check for +error printk some message if it is not -EPROBE_DEFER and return the error. +This pattern is simple but requires adding few lines after any resource +acquisition code, as a result it is often omitted or implemented only +partially. +dev_err_probe helps to replace such code sequences with simple call, +so code: + if (err != -EPROBE_DEFER) + dev_err(dev, ...); + return err; +becomes: + return dev_err_probe(dev, err, ...); + +Signed-off-by: Andrzej Hajda +Reviewed-by: Rafael J. Wysocki +Reviewed-by: Mark Brown +Reviewed-by: Andy Shevchenko +Link: https://lore.kernel.org/r/20200713144324.23654-2-a.hajda@samsung.com +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: cd136706b4f9 ("USB: bcma: Make GPIO explicitly optional") +Signed-off-by: Sasha Levin +--- + drivers/base/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ + include/linux/device.h | 3 +++ + 2 files changed, 45 insertions(+) + +diff --git a/drivers/base/core.c b/drivers/base/core.c +index 6e380ad9d08a..b66647277d52 100644 +--- a/drivers/base/core.c ++++ b/drivers/base/core.c +@@ -3334,6 +3334,48 @@ define_dev_printk_level(_dev_info, KERN_INFO); + + #endif + ++/** ++ * dev_err_probe - probe error check and log helper ++ * @dev: the pointer to the struct device ++ * @err: error value to test ++ * @fmt: printf-style format string ++ * @...: arguments as specified in the format string ++ * ++ * This helper implements common pattern present in probe functions for error ++ * checking: print debug or error message depending if the error value is ++ * -EPROBE_DEFER and propagate error upwards. ++ * It replaces code sequence: ++ * if (err != -EPROBE_DEFER) ++ * dev_err(dev, ...); ++ * else ++ * dev_dbg(dev, ...); ++ * return err; ++ * with ++ * return dev_err_probe(dev, err, ...); ++ * ++ * Returns @err. ++ * ++ */ ++int dev_err_probe(const struct device *dev, int err, const char *fmt, ...) ++{ ++ struct va_format vaf; ++ va_list args; ++ ++ va_start(args, fmt); ++ vaf.fmt = fmt; ++ vaf.va = &args; ++ ++ if (err != -EPROBE_DEFER) ++ dev_err(dev, "error %d: %pV", err, &vaf); ++ else ++ dev_dbg(dev, "error %d: %pV", err, &vaf); ++ ++ va_end(args); ++ ++ return err; ++} ++EXPORT_SYMBOL_GPL(dev_err_probe); ++ + static inline bool fwnode_is_primary(struct fwnode_handle *fwnode) + { + return fwnode && !IS_ERR(fwnode->secondary); +diff --git a/include/linux/device.h b/include/linux/device.h +index 37e359d81a86..0e38740fc53b 100644 +--- a/include/linux/device.h ++++ b/include/linux/device.h +@@ -1579,6 +1579,9 @@ do { \ + WARN_ONCE(condition, "%s %s: " format, \ + dev_driver_string(dev), dev_name(dev), ## arg) + ++extern __printf(3, 4) ++int dev_err_probe(const struct device *dev, int err, const char *fmt, ...); ++ + /* Create alias, so I can be autoloaded. */ + #define MODULE_ALIAS_CHARDEV(major,minor) \ + MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) +-- +2.35.1 + diff --git a/queue-4.19/iio-ms5611-simplify-io-callback-parameters.patch b/queue-4.19/iio-ms5611-simplify-io-callback-parameters.patch new file mode 100644 index 00000000000..bf1350de469 --- /dev/null +++ b/queue-4.19/iio-ms5611-simplify-io-callback-parameters.patch @@ -0,0 +1,188 @@ +From 8b33d8fdd8b1398c16a0e523f8e2a7f51d1776e4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 20 Oct 2021 16:21:10 +0200 +Subject: iio: ms5611: Simplify IO callback parameters + +From: Lars-Peter Clausen + +[ Upstream commit dc19fa63ad80a636fdbc1a02153d1ab140cb901f ] + +The ms5611 passes &indio_dev->dev as a parameter to all its IO callbacks +only to directly cast the struct device back to struct iio_dev. And the +struct iio_dev is then only used to get the drivers state struct. + +Simplify this a bit by passing the state struct directly. This makes it a +bit easier to follow what the code is doing. + +Signed-off-by: Lars-Peter Clausen +Link: https://lore.kernel.org/r/20211020142110.7060-1-lars@metafoo.de +Signed-off-by: Jonathan Cameron +Stable-dep-of: 17f442e7e475 ("iio: pressure: ms5611: fixed value compensation bug") +Signed-off-by: Sasha Levin +--- + drivers/iio/pressure/ms5611.h | 6 +++--- + drivers/iio/pressure/ms5611_core.c | 7 +++---- + drivers/iio/pressure/ms5611_i2c.c | 11 ++++------- + drivers/iio/pressure/ms5611_spi.c | 17 +++++++---------- + 4 files changed, 17 insertions(+), 24 deletions(-) + +diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h +index ead9e9f85894..236da38fb4b3 100644 +--- a/drivers/iio/pressure/ms5611.h ++++ b/drivers/iio/pressure/ms5611.h +@@ -53,9 +53,9 @@ struct ms5611_state { + const struct ms5611_osr *pressure_osr; + const struct ms5611_osr *temp_osr; + +- int (*reset)(struct device *dev); +- int (*read_prom_word)(struct device *dev, int index, u16 *word); +- int (*read_adc_temp_and_pressure)(struct device *dev, ++ int (*reset)(struct ms5611_state *st); ++ int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word); ++ int (*read_adc_temp_and_pressure)(struct ms5611_state *st, + s32 *temp, s32 *pressure); + + struct ms5611_chip_info *chip_info; +diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c +index f4ea886fdde4..6cbc58c601bb 100644 +--- a/drivers/iio/pressure/ms5611_core.c ++++ b/drivers/iio/pressure/ms5611_core.c +@@ -88,8 +88,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev) + struct ms5611_state *st = iio_priv(indio_dev); + + for (i = 0; i < MS5611_PROM_WORDS_NB; i++) { +- ret = st->read_prom_word(&indio_dev->dev, +- i, &st->chip_info->prom[i]); ++ ret = st->read_prom_word(st, i, &st->chip_info->prom[i]); + if (ret < 0) { + dev_err(&indio_dev->dev, + "failed to read prom at %d\n", i); +@@ -111,7 +110,7 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev, + int ret; + struct ms5611_state *st = iio_priv(indio_dev); + +- ret = st->read_adc_temp_and_pressure(&indio_dev->dev, temp, pressure); ++ ret = st->read_adc_temp_and_pressure(st, temp, pressure); + if (ret < 0) { + dev_err(&indio_dev->dev, + "failed to read temperature and pressure\n"); +@@ -199,7 +198,7 @@ static int ms5611_reset(struct iio_dev *indio_dev) + int ret; + struct ms5611_state *st = iio_priv(indio_dev); + +- ret = st->reset(&indio_dev->dev); ++ ret = st->reset(st); + if (ret < 0) { + dev_err(&indio_dev->dev, "failed to reset device\n"); + return ret; +diff --git a/drivers/iio/pressure/ms5611_i2c.c b/drivers/iio/pressure/ms5611_i2c.c +index 55fb5fc0b6ea..d78db17d6568 100644 +--- a/drivers/iio/pressure/ms5611_i2c.c ++++ b/drivers/iio/pressure/ms5611_i2c.c +@@ -21,17 +21,15 @@ + + #include "ms5611.h" + +-static int ms5611_i2c_reset(struct device *dev) ++static int ms5611_i2c_reset(struct ms5611_state *st) + { +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); +- + return i2c_smbus_write_byte(st->client, MS5611_RESET); + } + +-static int ms5611_i2c_read_prom_word(struct device *dev, int index, u16 *word) ++static int ms5611_i2c_read_prom_word(struct ms5611_state *st, int index, ++ u16 *word) + { + int ret; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + + ret = i2c_smbus_read_word_swapped(st->client, + MS5611_READ_PROM_WORD + (index << 1)); +@@ -58,11 +56,10 @@ static int ms5611_i2c_read_adc(struct ms5611_state *st, s32 *val) + return 0; + } + +-static int ms5611_i2c_read_adc_temp_and_pressure(struct device *dev, ++static int ms5611_i2c_read_adc_temp_and_pressure(struct ms5611_state *st, + s32 *temp, s32 *pressure) + { + int ret; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + const struct ms5611_osr *osr = st->temp_osr; + + ret = i2c_smbus_write_byte(st->client, osr->cmd); +diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c +index a582515ae2e6..42983d0736be 100644 +--- a/drivers/iio/pressure/ms5611_spi.c ++++ b/drivers/iio/pressure/ms5611_spi.c +@@ -16,18 +16,17 @@ + + #include "ms5611.h" + +-static int ms5611_spi_reset(struct device *dev) ++static int ms5611_spi_reset(struct ms5611_state *st) + { + u8 cmd = MS5611_RESET; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + + return spi_write_then_read(st->client, &cmd, 1, NULL, 0); + } + +-static int ms5611_spi_read_prom_word(struct device *dev, int index, u16 *word) ++static int ms5611_spi_read_prom_word(struct ms5611_state *st, int index, ++ u16 *word) + { + int ret; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + + ret = spi_w8r16be(st->client, MS5611_READ_PROM_WORD + (index << 1)); + if (ret < 0) +@@ -38,11 +37,10 @@ static int ms5611_spi_read_prom_word(struct device *dev, int index, u16 *word) + return 0; + } + +-static int ms5611_spi_read_adc(struct device *dev, s32 *val) ++static int ms5611_spi_read_adc(struct ms5611_state *st, s32 *val) + { + int ret; + u8 buf[3] = { MS5611_READ_ADC }; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + + ret = spi_write_then_read(st->client, buf, 1, buf, 3); + if (ret < 0) +@@ -53,11 +51,10 @@ static int ms5611_spi_read_adc(struct device *dev, s32 *val) + return 0; + } + +-static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, ++static int ms5611_spi_read_adc_temp_and_pressure(struct ms5611_state *st, + s32 *temp, s32 *pressure) + { + int ret; +- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + const struct ms5611_osr *osr = st->temp_osr; + + /* +@@ -69,7 +66,7 @@ static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, + return ret; + + usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); +- ret = ms5611_spi_read_adc(dev, temp); ++ ret = ms5611_spi_read_adc(st, temp); + if (ret < 0) + return ret; + +@@ -79,7 +76,7 @@ static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, + return ret; + + usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); +- return ms5611_spi_read_adc(dev, pressure); ++ return ms5611_spi_read_adc(st, pressure); + } + + static int ms5611_spi_probe(struct spi_device *spi) +-- +2.35.1 + diff --git a/queue-4.19/iio-pressure-ms5611-fixed-value-compensation-bug.patch b/queue-4.19/iio-pressure-ms5611-fixed-value-compensation-bug.patch new file mode 100644 index 00000000000..7b2db3635c6 --- /dev/null +++ b/queue-4.19/iio-pressure-ms5611-fixed-value-compensation-bug.patch @@ -0,0 +1,173 @@ +From d3d42ea85abad4bce3973dfa26097b2538141c11 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 21 Oct 2022 15:58:20 +0200 +Subject: iio: pressure: ms5611: fixed value compensation bug + +From: Mitja Spes + +[ Upstream commit 17f442e7e47579d3881fc4d47354eaef09302e6f ] + +When using multiple instances of this driver the compensation PROM was +overwritten by the last initialized sensor. Now each sensor has own PROM +storage. + +Signed-off-by: Mitja Spes +Fixes: 9690d81a02dc ("iio: pressure: ms5611: add support for MS5607 temperature and pressure sensor") +Link: https://lore.kernel.org/r/20221021135827.1444793-2-mitja@lxnav.com +Cc: +Signed-off-by: Jonathan Cameron +Signed-off-by: Sasha Levin +--- + drivers/iio/pressure/ms5611.h | 12 +++---- + drivers/iio/pressure/ms5611_core.c | 51 ++++++++++++++++-------------- + 2 files changed, 31 insertions(+), 32 deletions(-) + +diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h +index 236da38fb4b3..afcd622841dd 100644 +--- a/drivers/iio/pressure/ms5611.h ++++ b/drivers/iio/pressure/ms5611.h +@@ -28,13 +28,6 @@ enum { + MS5607, + }; + +-struct ms5611_chip_info { +- u16 prom[MS5611_PROM_WORDS_NB]; +- +- int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info, +- s32 *temp, s32 *pressure); +-}; +- + /* + * OverSampling Rate descriptor. + * Warning: cmd MUST be kept aligned on a word boundary (see +@@ -53,12 +46,15 @@ struct ms5611_state { + const struct ms5611_osr *pressure_osr; + const struct ms5611_osr *temp_osr; + ++ u16 prom[MS5611_PROM_WORDS_NB]; ++ + int (*reset)(struct ms5611_state *st); + int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word); + int (*read_adc_temp_and_pressure)(struct ms5611_state *st, + s32 *temp, s32 *pressure); + +- struct ms5611_chip_info *chip_info; ++ int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp, ++ s32 *pressure); + struct regulator *vdd; + }; + +diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c +index 6cbc58c601bb..5c7a734ede54 100644 +--- a/drivers/iio/pressure/ms5611_core.c ++++ b/drivers/iio/pressure/ms5611_core.c +@@ -88,7 +88,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev) + struct ms5611_state *st = iio_priv(indio_dev); + + for (i = 0; i < MS5611_PROM_WORDS_NB; i++) { +- ret = st->read_prom_word(st, i, &st->chip_info->prom[i]); ++ ret = st->read_prom_word(st, i, &st->prom[i]); + if (ret < 0) { + dev_err(&indio_dev->dev, + "failed to read prom at %d\n", i); +@@ -96,7 +96,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev) + } + } + +- if (!ms5611_prom_is_valid(st->chip_info->prom, MS5611_PROM_WORDS_NB)) { ++ if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) { + dev_err(&indio_dev->dev, "PROM integrity check failed\n"); + return -ENODEV; + } +@@ -117,21 +117,20 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev, + return ret; + } + +- return st->chip_info->temp_and_pressure_compensate(st->chip_info, +- temp, pressure); ++ return st->compensate_temp_and_pressure(st, temp, pressure); + } + +-static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info, ++static int ms5611_temp_and_pressure_compensate(struct ms5611_state *st, + s32 *temp, s32 *pressure) + { + s32 t = *temp, p = *pressure; + s64 off, sens, dt; + +- dt = t - (chip_info->prom[5] << 8); +- off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7); +- sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8); ++ dt = t - (st->prom[5] << 8); ++ off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7); ++ sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8); + +- t = 2000 + ((chip_info->prom[6] * dt) >> 23); ++ t = 2000 + ((st->prom[6] * dt) >> 23); + if (t < 2000) { + s64 off2, sens2, t2; + +@@ -157,17 +156,17 @@ static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_inf + return 0; + } + +-static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info, ++static int ms5607_temp_and_pressure_compensate(struct ms5611_state *st, + s32 *temp, s32 *pressure) + { + s32 t = *temp, p = *pressure; + s64 off, sens, dt; + +- dt = t - (chip_info->prom[5] << 8); +- off = ((s64)chip_info->prom[2] << 17) + ((chip_info->prom[4] * dt) >> 6); +- sens = ((s64)chip_info->prom[1] << 16) + ((chip_info->prom[3] * dt) >> 7); ++ dt = t - (st->prom[5] << 8); ++ off = ((s64)st->prom[2] << 17) + ((st->prom[4] * dt) >> 6); ++ sens = ((s64)st->prom[1] << 16) + ((st->prom[3] * dt) >> 7); + +- t = 2000 + ((chip_info->prom[6] * dt) >> 23); ++ t = 2000 + ((st->prom[6] * dt) >> 23); + if (t < 2000) { + s64 off2, sens2, t2, tmp; + +@@ -345,15 +344,6 @@ static int ms5611_write_raw(struct iio_dev *indio_dev, + + static const unsigned long ms5611_scan_masks[] = {0x3, 0}; + +-static struct ms5611_chip_info chip_info_tbl[] = { +- [MS5611] = { +- .temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate, +- }, +- [MS5607] = { +- .temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate, +- } +-}; +- + static const struct iio_chan_spec ms5611_channels[] = { + { + .type = IIO_PRESSURE, +@@ -436,7 +426,20 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, + struct ms5611_state *st = iio_priv(indio_dev); + + mutex_init(&st->lock); +- st->chip_info = &chip_info_tbl[type]; ++ ++ switch (type) { ++ case MS5611: ++ st->compensate_temp_and_pressure = ++ ms5611_temp_and_pressure_compensate; ++ break; ++ case MS5607: ++ st->compensate_temp_and_pressure = ++ ms5607_temp_and_pressure_compensate; ++ break; ++ default: ++ return -EINVAL; ++ } ++ + st->temp_osr = + &ms5611_avail_temp_osr[ARRAY_SIZE(ms5611_avail_temp_osr) - 1]; + st->pressure_osr = +-- +2.35.1 + diff --git a/queue-4.19/revert-usb-bcma-add-a-check-for-devm_gpiod_get.patch b/queue-4.19/revert-usb-bcma-add-a-check-for-devm_gpiod_get.patch new file mode 100644 index 00000000000..e545fdc864f --- /dev/null +++ b/queue-4.19/revert-usb-bcma-add-a-check-for-devm_gpiod_get.patch @@ -0,0 +1,57 @@ +From 7881f0f70cc03028e6764bc1a63824c0e4825fbf Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 31 Aug 2021 08:54:19 +0200 +Subject: Revert "USB: bcma: Add a check for devm_gpiod_get" +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Rafał Miłecki + +[ Upstream commit d91adc5322ab53df4b6d1989242bfb6c63163eb2 ] + +This reverts commit f3de5d857bb2362b00e2a8d4bc886cd49dcb66db. + +That commit broke USB on all routers that have USB always powered on and +don't require toggling any GPIO. It's a majority of devices actually. + +The original code worked and seemed safe: vcc GPIO is optional and +bcma_hci_platform_power_gpio() takes care of checking the pointer before +using it. + +This revert fixes: +[ 10.801127] bcma_hcd: probe of bcma0:11 failed with error -2 + +Fixes: f3de5d857bb2 ("USB: bcma: Add a check for devm_gpiod_get") +Cc: stable +Cc: Chuhong Yuan +Signed-off-by: Rafał Miłecki +Link: https://lore.kernel.org/r/20210831065419.18371-1-zajec5@gmail.com +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: cd136706b4f9 ("USB: bcma: Make GPIO explicitly optional") +Signed-off-by: Sasha Levin +--- + drivers/usb/host/bcma-hcd.c | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c +index 652fa29beb27..2400a826397a 100644 +--- a/drivers/usb/host/bcma-hcd.c ++++ b/drivers/usb/host/bcma-hcd.c +@@ -406,12 +406,9 @@ static int bcma_hcd_probe(struct bcma_device *core) + return -ENOMEM; + usb_dev->core = core; + +- if (core->dev.of_node) { ++ if (core->dev.of_node) + usb_dev->gpio_desc = devm_gpiod_get(&core->dev, "vcc", + GPIOD_OUT_HIGH); +- if (IS_ERR(usb_dev->gpio_desc)) +- return PTR_ERR(usb_dev->gpio_desc); +- } + + switch (core->id.id) { + case BCMA_CORE_USB20_HOST: +-- +2.35.1 + diff --git a/queue-4.19/series b/queue-4.19/series index 75cbe360116..ad8123fb503 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -37,3 +37,11 @@ kbuild-fix-wimplicit-function-declaration-in-license_is_gpl_compatible.patch iio-light-apds9960-fix-wrong-register-for-gesture-gain.patch iio-core-fix-entry-not-deleted-when-iio_register_sw_trigger_type-fails.patch nios2-add-force-for-vmlinuz.gz.patch +iio-ms5611-simplify-io-callback-parameters.patch +iio-pressure-ms5611-fixed-value-compensation-bug.patch +ceph-do-not-update-snapshot-context-when-there-is-no.patch +ceph-avoid-putting-the-realm-twice-when-decoding-sna.patch +usb-bcma-add-a-check-for-devm_gpiod_get.patch +driver-core-add-device-probe-log-helper.patch +revert-usb-bcma-add-a-check-for-devm_gpiod_get.patch +usb-bcma-make-gpio-explicitly-optional.patch diff --git a/queue-4.19/usb-bcma-add-a-check-for-devm_gpiod_get.patch b/queue-4.19/usb-bcma-add-a-check-for-devm_gpiod_get.patch new file mode 100644 index 00000000000..f44c97bccce --- /dev/null +++ b/queue-4.19/usb-bcma-add-a-check-for-devm_gpiod_get.patch @@ -0,0 +1,43 @@ +From d66cf0f9f69975c272707f73673ed9141267839a Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 16 Oct 2019 16:35:32 +0800 +Subject: USB: bcma: Add a check for devm_gpiod_get + +From: Chuhong Yuan + +[ Upstream commit f3de5d857bb2362b00e2a8d4bc886cd49dcb66db ] + +bcma_hcd_probe misses a check for devm_gpiod_get and may miss +the error. +Add a check for it and return the error if a failure occurs. + +Signed-off-by: Chuhong Yuan +Link: https://lore.kernel.org/r/20191016083531.5734-1-hslester96@gmail.com +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: cd136706b4f9 ("USB: bcma: Make GPIO explicitly optional") +Signed-off-by: Sasha Levin +--- + drivers/usb/host/bcma-hcd.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c +index 2400a826397a..652fa29beb27 100644 +--- a/drivers/usb/host/bcma-hcd.c ++++ b/drivers/usb/host/bcma-hcd.c +@@ -406,9 +406,12 @@ static int bcma_hcd_probe(struct bcma_device *core) + return -ENOMEM; + usb_dev->core = core; + +- if (core->dev.of_node) ++ if (core->dev.of_node) { + usb_dev->gpio_desc = devm_gpiod_get(&core->dev, "vcc", + GPIOD_OUT_HIGH); ++ if (IS_ERR(usb_dev->gpio_desc)) ++ return PTR_ERR(usb_dev->gpio_desc); ++ } + + switch (core->id.id) { + case BCMA_CORE_USB20_HOST: +-- +2.35.1 + diff --git a/queue-4.19/usb-bcma-make-gpio-explicitly-optional.patch b/queue-4.19/usb-bcma-make-gpio-explicitly-optional.patch new file mode 100644 index 00000000000..18be8a09d1c --- /dev/null +++ b/queue-4.19/usb-bcma-make-gpio-explicitly-optional.patch @@ -0,0 +1,71 @@ +From ac44493f24a7b75ab8b62b826875b87ca28d51bf Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 7 Nov 2022 10:07:53 +0100 +Subject: USB: bcma: Make GPIO explicitly optional +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Linus Walleij + +[ Upstream commit cd136706b4f925aa5d316642543babac90d45910 ] + +What the code does is to not check the return value from +devm_gpiod_get() and then avoid using an erroneous GPIO descriptor +with IS_ERR_OR_NULL(). + +This will miss real errors from the GPIO core that should not be +ignored, such as probe deferral. + +Instead request the GPIO as explicitly optional, which means that +if it doesn't exist, the descriptor returned will be NULL. + +Then we can add error handling and also avoid just doing this on +the device tree path, and simplify the site where the optional +GPIO descriptor is used. + +There were some problems with cleaning up this GPIO descriptor +use in the past, but this is the proper way to deal with it. + +Cc: Rafał Miłecki +Cc: Chuhong Yuan +Signed-off-by: Linus Walleij +Cc: stable +Link: https://lore.kernel.org/r/20221107090753.1404679-1-linus.walleij@linaro.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/host/bcma-hcd.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c +index 2400a826397a..d8f2af8fb89d 100644 +--- a/drivers/usb/host/bcma-hcd.c ++++ b/drivers/usb/host/bcma-hcd.c +@@ -285,7 +285,7 @@ static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val) + { + struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev); + +- if (IS_ERR_OR_NULL(usb_dev->gpio_desc)) ++ if (!usb_dev->gpio_desc) + return; + + gpiod_set_value(usb_dev->gpio_desc, val); +@@ -406,9 +406,11 @@ static int bcma_hcd_probe(struct bcma_device *core) + return -ENOMEM; + usb_dev->core = core; + +- if (core->dev.of_node) +- usb_dev->gpio_desc = devm_gpiod_get(&core->dev, "vcc", +- GPIOD_OUT_HIGH); ++ usb_dev->gpio_desc = devm_gpiod_get_optional(&core->dev, "vcc", ++ GPIOD_OUT_HIGH); ++ if (IS_ERR(usb_dev->gpio_desc)) ++ return dev_err_probe(&core->dev, PTR_ERR(usb_dev->gpio_desc), ++ "error obtaining VCC GPIO"); + + switch (core->id.id) { + case BCMA_CORE_USB20_HOST: +-- +2.35.1 +