Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'iio-fixes-for-7.0c' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus

Jonathan writes:

IIO: 3rd set of fixes for the 7.0 cycle.

Note that this pull is in addition to the 2nd set of such fixes that are
waiting to be picked up. Absolutely fine to queue these for the merge
window if that makes more sense.

Usual mixed back of ancient issues surfacing and newer problems.

adi,ad57770r
- Stop eating an error in read_raw.
adi,adxl313
- Check return of regmap_write() instead of ignoring it in one place.
adi,adxl355
- Fix the description of the temperature channel to be unsigned rather
than signed.
bosch,bmi160
- Avoid use of uninitialized data.
- Fix validation of small reference voltages.
hid-sensor-rotation:
- The timestamp location in this driver has unfortunately been broken for
a long time. Given it was correct for 6 years and then broken for the
next 6 years, use a one off hack to duplicate it in both locations.
The issue was as a result of the unique nature of quaternion
representation combined with large precision resulting in an
128 bit aligned channel.
nxp,sar-adc
- Avoid leaking a dma channel.
rfdigital,rfd77402
- Close a race between reinit_completion() and the irq happening.
ti,adc161s626
- Fix up buffer handling on big endian hosts which was broken due to
casting of pointers to different sized integers.
- Ensure a DMA safe buffer is used.
vishay,vcnl4035
- Fix up buffer handling on big endian hosts which was broken due to
casting of pointers to different sized integers.
vishay,veml6070
- Fix return value mess up that occurred when doing a guard() conversion.

* tag 'iio-fixes-for-7.0c' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
iio: light: veml6070: fix veml6070_read() return value
iio: adc: nxp-sar-adc: Fix DMA channel leak in trigger mode
iio: accel: adxl313: add missing error check in predisable
iio: dac: ad5770r: fix error return in ad5770r_read_raw()
iio: accel: fix ADXL355 temperature signature value
iio: light: vcnl4035: fix scan buffer on big-endian
iio: adc: ti-adc161s626: use DMA-safe memory for spi_read()
iio: adc: ti-adc161s626: fix buffer read on big-endian
iio: dac: mcp47feb02: Fix Vref validation [1-999] case
iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
iio: orientation: hid-sensor-rotation: add timestamp hack to not break userspace
iio: proximity: rfd77402: Fix completion race condition in IRQ mode

+92 -79
+2
drivers/iio/accel/adxl313_core.c
··· 998 998 999 999 ret = regmap_write(data->regmap, ADXL313_REG_FIFO_CTL, 1000 1000 FIELD_PREP(ADXL313_REG_FIFO_CTL_MODE_MSK, ADXL313_FIFO_BYPASS)); 1001 + if (ret) 1002 + return ret; 1001 1003 1002 1004 ret = regmap_write(data->regmap, ADXL313_REG_INT_ENABLE, 0); 1003 1005 if (ret)
+1 -1
drivers/iio/accel/adxl355_core.c
··· 745 745 BIT(IIO_CHAN_INFO_OFFSET), 746 746 .scan_index = 3, 747 747 .scan_type = { 748 - .sign = 's', 748 + .sign = 'u', 749 749 .realbits = 12, 750 750 .storagebits = 16, 751 751 .endianness = IIO_BE,
+5 -4
drivers/iio/adc/nxp-sar-adc.c
··· 718 718 struct nxp_sar_adc *info = iio_priv(indio_dev); 719 719 int ret; 720 720 721 + info->dma_chan = dma_request_chan(indio_dev->dev.parent, "rx"); 722 + if (IS_ERR(info->dma_chan)) 723 + return PTR_ERR(info->dma_chan); 724 + 721 725 nxp_sar_adc_dma_channels_enable(info, *indio_dev->active_scan_mask); 722 726 723 727 nxp_sar_adc_dma_cfg(info, true); ··· 742 738 out_dma_channels_disable: 743 739 nxp_sar_adc_dma_cfg(info, false); 744 740 nxp_sar_adc_dma_channels_disable(info, *indio_dev->active_scan_mask); 741 + dma_release_channel(info->dma_chan); 745 742 746 743 return ret; 747 744 } ··· 769 764 int current_mode = iio_device_get_current_mode(indio_dev); 770 765 unsigned long channel; 771 766 int ret; 772 - 773 - info->dma_chan = dma_request_chan(indio_dev->dev.parent, "rx"); 774 - if (IS_ERR(info->dma_chan)) 775 - return PTR_ERR(info->dma_chan); 776 767 777 768 info->channels_used = 0; 778 769
+20 -21
drivers/iio/adc/ti-adc161s626.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/err.h> 17 17 #include <linux/spi/spi.h> 18 + #include <linux/unaligned.h> 18 19 #include <linux/iio/iio.h> 19 20 #include <linux/iio/trigger.h> 20 21 #include <linux/iio/buffer.h> ··· 71 70 72 71 u8 read_size; 73 72 u8 shift; 74 - 75 - u8 buffer[16] __aligned(IIO_DMA_MINALIGN); 73 + u8 buf[3] __aligned(IIO_DMA_MINALIGN); 76 74 }; 77 75 78 76 static int ti_adc_read_measurement(struct ti_adc_data *data, ··· 80 80 int ret; 81 81 82 82 switch (data->read_size) { 83 - case 2: { 84 - __be16 buf; 85 - 86 - ret = spi_read(data->spi, (void *) &buf, 2); 83 + case 2: 84 + ret = spi_read(data->spi, data->buf, 2); 87 85 if (ret) 88 86 return ret; 89 87 90 - *val = be16_to_cpu(buf); 88 + *val = get_unaligned_be16(data->buf); 91 89 break; 92 - } 93 - case 3: { 94 - __be32 buf; 95 - 96 - ret = spi_read(data->spi, (void *) &buf, 3); 90 + case 3: 91 + ret = spi_read(data->spi, data->buf, 3); 97 92 if (ret) 98 93 return ret; 99 94 100 - *val = be32_to_cpu(buf) >> 8; 95 + *val = get_unaligned_be24(data->buf); 101 96 break; 102 - } 103 97 default: 104 98 return -EINVAL; 105 99 } ··· 108 114 struct iio_poll_func *pf = private; 109 115 struct iio_dev *indio_dev = pf->indio_dev; 110 116 struct ti_adc_data *data = iio_priv(indio_dev); 111 - int ret; 117 + struct { 118 + s16 data; 119 + aligned_s64 timestamp; 120 + } scan = { }; 121 + int ret, val; 112 122 113 - ret = ti_adc_read_measurement(data, &indio_dev->channels[0], 114 - (int *) &data->buffer); 115 - if (!ret) 116 - iio_push_to_buffers_with_timestamp(indio_dev, 117 - data->buffer, 118 - iio_get_time_ns(indio_dev)); 123 + ret = ti_adc_read_measurement(data, &indio_dev->channels[0], &val); 124 + if (ret) 125 + goto exit_notify_done; 119 126 127 + scan.data = val; 128 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev)); 129 + 130 + exit_notify_done: 120 131 iio_trigger_notify_done(indio_dev->trig); 121 132 122 133 return IRQ_HANDLED;
+1 -1
drivers/iio/dac/ad5770r.c
··· 322 322 chan->address, 323 323 st->transf_buf, 2); 324 324 if (ret) 325 - return 0; 325 + return ret; 326 326 327 327 buf16 = get_unaligned_le16(st->transf_buf); 328 328 *val = buf16 >> 2;
+22 -27
drivers/iio/dac/mcp47feb02.c
··· 65 65 #define MCP47FEB02_MAX_SCALES_CH 3 66 66 #define MCP47FEB02_DAC_WIPER_UNLOCKED 0 67 67 #define MCP47FEB02_NORMAL_OPERATION 0 68 - #define MCP47FEB02_INTERNAL_BAND_GAP_mV 2440 68 + #define MCP47FEB02_INTERNAL_BAND_GAP_uV 2440000 69 69 #define NV_DAC_ADDR_OFFSET 0x10 70 70 71 71 enum mcp47feb02_vref_mode { ··· 697 697 }; 698 698 699 699 static void mcp47feb02_init_scale(struct mcp47feb02_data *data, enum mcp47feb02_scale scale, 700 - int vref_mV, int scale_avail[]) 700 + int vref_uV, int scale_avail[]) 701 701 { 702 702 u32 value_micro, value_int; 703 703 u64 tmp; 704 704 705 - /* vref_mV should not be negative */ 706 - tmp = (u64)vref_mV * MICRO >> data->chip_features->resolution; 705 + /* vref_uV should not be negative */ 706 + tmp = (u64)vref_uV * MILLI >> data->chip_features->resolution; 707 707 value_int = div_u64_rem(tmp, MICRO, &value_micro); 708 708 scale_avail[scale * 2] = value_int; 709 709 scale_avail[scale * 2 + 1] = value_micro; 710 710 } 711 711 712 - static int mcp47feb02_init_scales_avail(struct mcp47feb02_data *data, int vdd_mV, 713 - int vref_mV, int vref1_mV) 712 + static int mcp47feb02_init_scales_avail(struct mcp47feb02_data *data, int vdd_uV, 713 + int vref_uV, int vref1_uV) 714 714 { 715 - struct device *dev = regmap_get_device(data->regmap); 716 715 int tmp_vref; 717 716 718 - mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_mV, data->scale); 717 + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_uV, data->scale); 719 718 720 719 if (data->use_vref) 721 - tmp_vref = vref_mV; 720 + tmp_vref = vref_uV; 722 721 else 723 - tmp_vref = MCP47FEB02_INTERNAL_BAND_GAP_mV; 722 + tmp_vref = MCP47FEB02_INTERNAL_BAND_GAP_uV; 724 723 725 724 mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X1, tmp_vref, data->scale); 726 725 mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X2, tmp_vref * 2, data->scale); 727 726 728 727 if (data->phys_channels >= 4) { 729 - mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_mV, data->scale_1); 730 - 731 - if (data->use_vref1 && vref1_mV <= 0) 732 - return dev_err_probe(dev, vref1_mV, "Invalid voltage for Vref1\n"); 728 + mcp47feb02_init_scale(data, MCP47FEB02_SCALE_VDD, vdd_uV, data->scale_1); 733 729 734 730 if (data->use_vref1) 735 - tmp_vref = vref1_mV; 731 + tmp_vref = vref1_uV; 736 732 else 737 - tmp_vref = MCP47FEB02_INTERNAL_BAND_GAP_mV; 733 + tmp_vref = MCP47FEB02_INTERNAL_BAND_GAP_uV; 738 734 739 735 mcp47feb02_init_scale(data, MCP47FEB02_SCALE_GAIN_X1, 740 736 tmp_vref, data->scale_1); ··· 1074 1078 return 0; 1075 1079 } 1076 1080 1077 - static int mcp47feb02_init_ch_scales(struct mcp47feb02_data *data, int vdd_mV, 1078 - int vref_mV, int vref1_mV) 1081 + static int mcp47feb02_init_ch_scales(struct mcp47feb02_data *data, int vdd_uV, 1082 + int vref_uV, int vref1_uV) 1079 1083 { 1080 1084 unsigned int i; 1081 1085 ··· 1083 1087 struct device *dev = regmap_get_device(data->regmap); 1084 1088 int ret; 1085 1089 1086 - ret = mcp47feb02_init_scales_avail(data, vdd_mV, vref_mV, vref1_mV); 1090 + ret = mcp47feb02_init_scales_avail(data, vdd_uV, vref_uV, vref1_uV); 1087 1091 if (ret) 1088 1092 return dev_err_probe(dev, ret, "failed to init scales for ch %u\n", i); 1089 1093 } ··· 1097 1101 struct device *dev = &client->dev; 1098 1102 struct mcp47feb02_data *data; 1099 1103 struct iio_dev *indio_dev; 1100 - int vref1_mV = 0; 1101 - int vref_mV = 0; 1102 - int vdd_mV; 1103 - int ret; 1104 + int vref1_uV, vref_uV, vdd_uV, ret; 1104 1105 1105 1106 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 1106 1107 if (!indio_dev) ··· 1134 1141 if (ret < 0) 1135 1142 return ret; 1136 1143 1137 - vdd_mV = ret / MILLI; 1144 + vdd_uV = ret; 1138 1145 1139 1146 ret = devm_regulator_get_enable_read_voltage(dev, "vref"); 1140 1147 if (ret > 0) { 1141 - vref_mV = ret / MILLI; 1148 + vref_uV = ret; 1142 1149 data->use_vref = true; 1143 1150 } else { 1151 + vref_uV = 0; 1144 1152 dev_dbg(dev, "using internal band gap as voltage reference.\n"); 1145 1153 dev_dbg(dev, "Vref is unavailable.\n"); 1146 1154 } ··· 1149 1155 if (chip_features->have_ext_vref1) { 1150 1156 ret = devm_regulator_get_enable_read_voltage(dev, "vref1"); 1151 1157 if (ret > 0) { 1152 - vref1_mV = ret / MILLI; 1158 + vref1_uV = ret; 1153 1159 data->use_vref1 = true; 1154 1160 } else { 1161 + vref1_uV = 0; 1155 1162 dev_dbg(dev, "using internal band gap as voltage reference 1.\n"); 1156 1163 dev_dbg(dev, "Vref1 is unavailable.\n"); 1157 1164 } ··· 1162 1167 if (ret) 1163 1168 return dev_err_probe(dev, ret, "Error initialising vref register\n"); 1164 1169 1165 - ret = mcp47feb02_init_ch_scales(data, vdd_mV, vref_mV, vref1_mV); 1170 + ret = mcp47feb02_init_ch_scales(data, vdd_uV, vref_uV, vref1_uV); 1166 1171 if (ret) 1167 1172 return ret; 1168 1173
+5 -10
drivers/iio/imu/bmi160/bmi160_core.c
··· 573 573 int_out_ctrl_shift = BMI160_INT1_OUT_CTRL_SHIFT; 574 574 int_latch_mask = BMI160_INT1_LATCH_MASK; 575 575 int_map_mask = BMI160_INT1_MAP_DRDY_EN; 576 + pin_name = "INT1"; 576 577 break; 577 578 case BMI160_PIN_INT2: 578 579 int_out_ctrl_shift = BMI160_INT2_OUT_CTRL_SHIFT; 579 580 int_latch_mask = BMI160_INT2_LATCH_MASK; 580 581 int_map_mask = BMI160_INT2_MAP_DRDY_EN; 582 + pin_name = "INT2"; 581 583 break; 584 + default: 585 + return -EINVAL; 582 586 } 583 587 int_out_ctrl_mask = BMI160_INT_OUT_CTRL_MASK << int_out_ctrl_shift; 584 588 ··· 616 612 ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_MAP, 617 613 int_map_mask, int_map_mask, 618 614 write_usleep); 619 - if (ret) { 620 - switch (pin) { 621 - case BMI160_PIN_INT1: 622 - pin_name = "INT1"; 623 - break; 624 - case BMI160_PIN_INT2: 625 - pin_name = "INT2"; 626 - break; 627 - } 615 + if (ret) 628 616 dev_err(dev, "Failed to configure %s IRQ pin", pin_name); 629 - } 630 617 631 618 return ret; 632 619 }
+12 -6
drivers/iio/light/vcnl4035.c
··· 103 103 struct iio_dev *indio_dev = pf->indio_dev; 104 104 struct vcnl4035_data *data = iio_priv(indio_dev); 105 105 /* Ensure naturally aligned timestamp */ 106 - u8 buffer[ALIGN(sizeof(u16), sizeof(s64)) + sizeof(s64)] __aligned(8) = { }; 106 + struct { 107 + u16 als_data; 108 + aligned_s64 timestamp; 109 + } buffer = { }; 110 + unsigned int val; 107 111 int ret; 108 112 109 - ret = regmap_read(data->regmap, VCNL4035_ALS_DATA, (int *)buffer); 113 + ret = regmap_read(data->regmap, VCNL4035_ALS_DATA, &val); 110 114 if (ret < 0) { 111 115 dev_err(&data->client->dev, 112 116 "Trigger consumer can't read from sensor.\n"); 113 117 goto fail_read; 114 118 } 115 - iio_push_to_buffers_with_timestamp(indio_dev, buffer, 116 - iio_get_time_ns(indio_dev)); 119 + 120 + buffer.als_data = val; 121 + iio_push_to_buffers_with_timestamp(indio_dev, &buffer, 122 + iio_get_time_ns(indio_dev)); 117 123 118 124 fail_read: 119 125 iio_trigger_notify_done(indio_dev->trig); ··· 387 381 .sign = 'u', 388 382 .realbits = 16, 389 383 .storagebits = 16, 390 - .endianness = IIO_LE, 384 + .endianness = IIO_CPU, 391 385 }, 392 386 }, 393 387 { ··· 401 395 .sign = 'u', 402 396 .realbits = 16, 403 397 .storagebits = 16, 404 - .endianness = IIO_LE, 398 + .endianness = IIO_CPU, 405 399 }, 406 400 }, 407 401 };
+1 -3
drivers/iio/light/veml6070.c
··· 134 134 if (ret < 0) 135 135 return ret; 136 136 137 - ret = (msb << 8) | lsb; 138 - 139 - return 0; 137 + return (msb << 8) | lsb; 140 138 } 141 139 142 140 static const struct iio_chan_spec veml6070_channels[] = {
+19 -3
drivers/iio/orientation/hid-sensor-rotation.c
··· 20 20 struct hid_sensor_hub_attribute_info quaternion; 21 21 struct { 22 22 IIO_DECLARE_QUATERNION(s32, sampled_vals); 23 - aligned_s64 timestamp; 23 + /* 24 + * ABI regression avoidance: There are two copies of the same 25 + * timestamp in case of userspace depending on broken alignment 26 + * from older kernels. 27 + */ 28 + aligned_s64 timestamp[2]; 24 29 } scan; 25 30 int scale_pre_decml; 26 31 int scale_post_decml; ··· 159 154 if (!rot_state->timestamp) 160 155 rot_state->timestamp = iio_get_time_ns(indio_dev); 161 156 162 - iio_push_to_buffers_with_timestamp(indio_dev, &rot_state->scan, 163 - rot_state->timestamp); 157 + /* 158 + * ABI regression avoidance: IIO previously had an incorrect 159 + * implementation of iio_push_to_buffers_with_timestamp() that 160 + * put the timestamp in the last 8 bytes of the buffer, which 161 + * was incorrect according to the IIO ABI. To avoid breaking 162 + * userspace that may be depending on this broken behavior, we 163 + * put the timestamp in both the correct place [0] and the old 164 + * incorrect place [1]. 165 + */ 166 + rot_state->scan.timestamp[0] = rot_state->timestamp; 167 + rot_state->scan.timestamp[1] = rot_state->timestamp; 168 + 169 + iio_push_to_buffers(indio_dev, &rot_state->scan); 164 170 165 171 rot_state->timestamp = 0; 166 172 }
+4 -3
drivers/iio/proximity/rfd77402.c
··· 173 173 struct i2c_client *client = data->client; 174 174 int val, ret; 175 175 176 - if (data->irq_en) { 177 - reinit_completion(&data->completion); 176 + if (data->irq_en) 178 177 return rfd77402_wait_for_irq(data); 179 - } 180 178 181 179 /* 182 180 * As per RFD77402 datasheet section '3.1.1 Single Measure', the ··· 201 203 RFD77402_STATUS_MCPU_ON); 202 204 if (ret < 0) 203 205 return ret; 206 + 207 + if (data->irq_en) 208 + reinit_completion(&data->completion); 204 209 205 210 ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R, 206 211 RFD77402_CMD_SINGLE |