Skip to content

Commit f9e0579

Browse files
Shi Haojic23
authored andcommitted
staging: iio: adt7316: replace sprintf() with sysfs_emit()
Convert several sprintf() calls to sysfs_emit() in the sysfs show functions, as it is the preferred helper and prevents potential buffer overruns. No functional changes intended. Signed-off-by: Shi Hao <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 02d44a1 commit f9e0579

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

drivers/staging/iio/addac/adt7316.c

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static ssize_t adt7316_show_enabled(struct device *dev,
216216
struct iio_dev *dev_info = dev_to_iio_dev(dev);
217217
struct adt7316_chip_info *chip = iio_priv(dev_info);
218218

219-
return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_EN));
219+
return sysfs_emit(buf, "%d\n", !!(chip->config1 & ADT7316_EN));
220220
}
221221

222222
static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
@@ -274,7 +274,7 @@ static ssize_t adt7316_show_select_ex_temp(struct device *dev,
274274
if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
275275
return -EPERM;
276276

277-
return sprintf(buf, "%d\n", !!(chip->config1 & ADT7516_SEL_EX_TEMP));
277+
return sysfs_emit(buf, "%d\n", !!(chip->config1 & ADT7516_SEL_EX_TEMP));
278278
}
279279

280280
static ssize_t adt7316_store_select_ex_temp(struct device *dev,
@@ -316,9 +316,9 @@ static ssize_t adt7316_show_mode(struct device *dev,
316316
struct adt7316_chip_info *chip = iio_priv(dev_info);
317317

318318
if (chip->config2 & ADT7316_AD_SINGLE_CH_MODE)
319-
return sprintf(buf, "single_channel\n");
319+
return sysfs_emit(buf, "single_channel\n");
320320

321-
return sprintf(buf, "round_robin\n");
321+
return sysfs_emit(buf, "round_robin\n");
322322
}
323323

324324
static ssize_t adt7316_store_mode(struct device *dev,
@@ -353,7 +353,7 @@ static ssize_t adt7316_show_all_modes(struct device *dev,
353353
struct device_attribute *attr,
354354
char *buf)
355355
{
356-
return sprintf(buf, "single_channel\nround_robin\n");
356+
return sysfs_emit(buf, "single_channel\nround_robin\n");
357357
}
358358

359359
static IIO_DEVICE_ATTR(all_modes, 0444, adt7316_show_all_modes, NULL, 0);
@@ -370,29 +370,29 @@ static ssize_t adt7316_show_ad_channel(struct device *dev,
370370

371371
switch (chip->config2 & ADT7516_AD_SINGLE_CH_MASK) {
372372
case ADT7316_AD_SINGLE_CH_VDD:
373-
return sprintf(buf, "0 - VDD\n");
373+
return sysfs_emit(buf, "0 - VDD\n");
374374
case ADT7316_AD_SINGLE_CH_IN:
375-
return sprintf(buf, "1 - Internal Temperature\n");
375+
return sysfs_emit(buf, "1 - Internal Temperature\n");
376376
case ADT7316_AD_SINGLE_CH_EX:
377377
if (((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) &&
378378
(chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)
379-
return sprintf(buf, "2 - AIN1\n");
379+
return sysfs_emit(buf, "2 - AIN1\n");
380380

381-
return sprintf(buf, "2 - External Temperature\n");
381+
return sysfs_emit(buf, "2 - External Temperature\n");
382382
case ADT7516_AD_SINGLE_CH_AIN2:
383383
if ((chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)
384-
return sprintf(buf, "3 - AIN2\n");
384+
return sysfs_emit(buf, "3 - AIN2\n");
385385

386-
return sprintf(buf, "N/A\n");
386+
return sysfs_emit(buf, "N/A\n");
387387
case ADT7516_AD_SINGLE_CH_AIN3:
388388
if (chip->config1 & ADT7516_SEL_AIN3)
389-
return sprintf(buf, "4 - AIN3\n");
389+
return sysfs_emit(buf, "4 - AIN3\n");
390390

391-
return sprintf(buf, "N/A\n");
391+
return sysfs_emit(buf, "N/A\n");
392392
case ADT7516_AD_SINGLE_CH_AIN4:
393-
return sprintf(buf, "5 - AIN4\n");
393+
return sysfs_emit(buf, "5 - AIN4\n");
394394
default:
395-
return sprintf(buf, "N/A\n");
395+
return sysfs_emit(buf, "N/A\n");
396396
}
397397
}
398398

@@ -453,10 +453,10 @@ static ssize_t adt7316_show_all_ad_channels(struct device *dev,
453453
return -EPERM;
454454

455455
if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
456-
return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n"
456+
return sysfs_emit(buf, "0 - VDD\n1 - Internal Temperature\n"
457457
"2 - External Temperature or AIN1\n"
458458
"3 - AIN2\n4 - AIN3\n5 - AIN4\n");
459-
return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n"
459+
return sysfs_emit(buf, "0 - VDD\n1 - Internal Temperature\n"
460460
"2 - External Temperature\n");
461461
}
462462

@@ -470,7 +470,7 @@ static ssize_t adt7316_show_disable_averaging(struct device *dev,
470470
struct iio_dev *dev_info = dev_to_iio_dev(dev);
471471
struct adt7316_chip_info *chip = iio_priv(dev_info);
472472

473-
return sprintf(buf, "%d\n",
473+
return sysfs_emit(buf, "%d\n",
474474
!!(chip->config2 & ADT7316_DISABLE_AVERAGING));
475475
}
476476

@@ -509,7 +509,7 @@ static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev,
509509
struct iio_dev *dev_info = dev_to_iio_dev(dev);
510510
struct adt7316_chip_info *chip = iio_priv(dev_info);
511511

512-
return sprintf(buf, "%d\n",
512+
return sysfs_emit(buf, "%d\n",
513513
!!(chip->config2 & ADT7316_EN_SMBUS_TIMEOUT));
514514
}
515515

@@ -548,7 +548,7 @@ static ssize_t adt7316_show_powerdown(struct device *dev,
548548
struct iio_dev *dev_info = dev_to_iio_dev(dev);
549549
struct adt7316_chip_info *chip = iio_priv(dev_info);
550550

551-
return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_PD));
551+
return sysfs_emit(buf, "%d\n", !!(chip->config1 & ADT7316_PD));
552552
}
553553

554554
static ssize_t adt7316_store_powerdown(struct device *dev,
@@ -586,7 +586,7 @@ static ssize_t adt7316_show_fast_ad_clock(struct device *dev,
586586
struct iio_dev *dev_info = dev_to_iio_dev(dev);
587587
struct adt7316_chip_info *chip = iio_priv(dev_info);
588588

589-
return sprintf(buf, "%d\n", !!(chip->config3 & ADT7316_ADCLK_22_5));
589+
return sysfs_emit(buf, "%d\n", !!(chip->config3 & ADT7316_ADCLK_22_5));
590590
}
591591

592592
static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
@@ -626,10 +626,10 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev,
626626

627627
if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) {
628628
if (chip->id != ID_ADT7318 && chip->id != ID_ADT7519)
629-
return sprintf(buf, "1 (10 bits)\n");
629+
return sysfs_emit(buf, "1 (10 bits)\n");
630630
}
631631

632-
return sprintf(buf, "0 (8 bits)\n");
632+
return sysfs_emit(buf, "0 (8 bits)\n");
633633
}
634634

635635
static ssize_t adt7316_store_da_high_resolution(struct device *dev,
@@ -673,7 +673,7 @@ static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev,
673673
if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
674674
return -EPERM;
675675

676-
return sprintf(buf, "%d\n",
676+
return sysfs_emit(buf, "%d\n",
677677
!!(chip->config3 & ADT7516_AIN_IN_VREF));
678678
}
679679

@@ -716,7 +716,7 @@ static ssize_t adt7316_show_enable_prop_DACA(struct device *dev,
716716
struct iio_dev *dev_info = dev_to_iio_dev(dev);
717717
struct adt7316_chip_info *chip = iio_priv(dev_info);
718718

719-
return sprintf(buf, "%d\n",
719+
return sysfs_emit(buf, "%d\n",
720720
!!(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA));
721721
}
722722

@@ -755,7 +755,7 @@ static ssize_t adt7316_show_enable_prop_DACB(struct device *dev,
755755
struct iio_dev *dev_info = dev_to_iio_dev(dev);
756756
struct adt7316_chip_info *chip = iio_priv(dev_info);
757757

758-
return sprintf(buf, "%d\n",
758+
return sysfs_emit(buf, "%d\n",
759759
!!(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB));
760760
}
761761

@@ -794,7 +794,7 @@ static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev,
794794
struct iio_dev *dev_info = dev_to_iio_dev(dev);
795795
struct adt7316_chip_info *chip = iio_priv(dev_info);
796796

797-
return sprintf(buf, "0x%x\n",
797+
return sysfs_emit(buf, "0x%x\n",
798798
chip->dac_config & ADT7316_DA_2VREF_CH_MASK);
799799
}
800800

@@ -838,20 +838,20 @@ static ssize_t adt7316_show_DAC_update_mode(struct device *dev,
838838
struct adt7316_chip_info *chip = iio_priv(dev_info);
839839

840840
if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC))
841-
return sprintf(buf, "manual\n");
841+
return sysfs_emit(buf, "manual\n");
842842

843843
switch (chip->dac_config & ADT7316_DA_EN_MODE_MASK) {
844844
case ADT7316_DA_EN_MODE_SINGLE:
845-
return sprintf(buf,
845+
return sysfs_emit(buf,
846846
"0 - auto at any MSB DAC writing\n");
847847
case ADT7316_DA_EN_MODE_AB_CD:
848-
return sprintf(buf,
848+
return sysfs_emit(buf,
849849
"1 - auto at MSB DAC AB and CD writing\n");
850850
case ADT7316_DA_EN_MODE_ABCD:
851-
return sprintf(buf,
851+
return sysfs_emit(buf,
852852
"2 - auto at MSB DAC ABCD writing\n");
853853
default: /* ADT7316_DA_EN_MODE_LDAC */
854-
return sprintf(buf, "3 - manual\n");
854+
return sysfs_emit(buf, "3 - manual\n");
855855
}
856856
}
857857

@@ -898,11 +898,11 @@ static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev,
898898
struct adt7316_chip_info *chip = iio_priv(dev_info);
899899

900900
if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDAC)
901-
return sprintf(buf, "0 - auto at any MSB DAC writing\n"
901+
return sysfs_emit(buf, "0 - auto at any MSB DAC writing\n"
902902
"1 - auto at MSB DAC AB and CD writing\n"
903903
"2 - auto at MSB DAC ABCD writing\n"
904904
"3 - manual\n");
905-
return sprintf(buf, "manual\n");
905+
return sysfs_emit(buf, "manual\n");
906906
}
907907

908908
static IIO_DEVICE_ATTR(all_DAC_update_modes, 0444,
@@ -955,7 +955,7 @@ static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev,
955955
struct iio_dev *dev_info = dev_to_iio_dev(dev);
956956
struct adt7316_chip_info *chip = iio_priv(dev_info);
957957

958-
return sprintf(buf, "%d\n",
958+
return sysfs_emit(buf, "%d\n",
959959
!!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_AB));
960960
}
961961

@@ -994,7 +994,7 @@ static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev,
994994
struct iio_dev *dev_info = dev_to_iio_dev(dev);
995995
struct adt7316_chip_info *chip = iio_priv(dev_info);
996996

997-
return sprintf(buf, "%d\n",
997+
return sysfs_emit(buf, "%d\n",
998998
!!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_CD));
999999
}
10001000

@@ -1034,10 +1034,10 @@ static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev,
10341034
struct adt7316_chip_info *chip = iio_priv(dev_info);
10351035

10361036
if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1037-
return sprintf(buf, "0x%x\n",
1037+
return sysfs_emit(buf, "0x%x\n",
10381038
(chip->ldac_config & ADT7516_DAC_IN_VREF_MASK) >>
10391039
ADT7516_DAC_IN_VREF_OFFSET);
1040-
return sprintf(buf, "%d\n",
1040+
return sysfs_emit(buf, "%d\n",
10411041
!!(chip->ldac_config & ADT7316_DAC_IN_VREF));
10421042
}
10431043

@@ -1128,7 +1128,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
11281128

11291129
data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
11301130
data |= (lsb & ADT7316_LSB_VDD_MASK) >> ADT7316_LSB_VDD_OFFSET;
1131-
return sprintf(buf, "%d\n", data);
1131+
return sysfs_emit(buf, "%d\n", data);
11321132
default: /* ex_temp and ain */
11331133
ret = chip->bus.read(chip->bus.client,
11341134
ADT7316_LSB_EX_TEMP_AIN, &lsb);
@@ -1146,7 +1146,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
11461146
(ADT7316_MSB_EX_TEMP - ADT7316_AD_MSB_DATA_BASE))));
11471147

11481148
if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1149-
return sprintf(buf, "%d\n", data);
1149+
return sysfs_emit(buf, "%d\n", data);
11501150

11511151
break;
11521152
}
@@ -1157,7 +1157,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
11571157
sign = '-';
11581158
}
11591159

1160-
return sprintf(buf, "%c%d.%.2d\n", sign,
1160+
return sysfs_emit(buf, "%c%d.%.2d\n", sign,
11611161
(data >> ADT7316_T_VALUE_FLOAT_OFFSET),
11621162
(data & ADT7316_T_VALUE_FLOAT_MASK) * 25);
11631163
}
@@ -1247,7 +1247,7 @@ static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip,
12471247
if (val & 0x80)
12481248
data -= 256;
12491249

1250-
return sprintf(buf, "%d\n", data);
1250+
return sysfs_emit(buf, "%d\n", data);
12511251
}
12521252

12531253
static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip,
@@ -1415,7 +1415,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
14151415
data = lsb >> ADT7316_DA_10_BIT_LSB_SHIFT;
14161416
data |= msb << offset;
14171417

1418-
return sprintf(buf, "%d\n", data);
1418+
return sysfs_emit(buf, "%d\n", data);
14191419
}
14201420

14211421
static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
@@ -1568,7 +1568,7 @@ static ssize_t adt7316_show_device_id(struct device *dev,
15681568
if (ret)
15691569
return -EIO;
15701570

1571-
return sprintf(buf, "%d\n", id);
1571+
return sysfs_emit(buf, "%d\n", id);
15721572
}
15731573

15741574
static IIO_DEVICE_ATTR(device_id, 0444, adt7316_show_device_id, NULL, 0);
@@ -1586,7 +1586,7 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev,
15861586
if (ret)
15871587
return -EIO;
15881588

1589-
return sprintf(buf, "%d\n", id);
1589+
return sysfs_emit(buf, "%d\n", id);
15901590
}
15911591

15921592
static IIO_DEVICE_ATTR(manufactorer_id, 0444,
@@ -1605,7 +1605,7 @@ static ssize_t adt7316_show_device_rev(struct device *dev,
16051605
if (ret)
16061606
return -EIO;
16071607

1608-
return sprintf(buf, "%d\n", rev);
1608+
return sysfs_emit(buf, "%d\n", rev);
16091609
}
16101610

16111611
static IIO_DEVICE_ATTR(device_rev, 0444, adt7316_show_device_rev, NULL, 0);
@@ -1624,9 +1624,9 @@ static ssize_t adt7316_show_bus_type(struct device *dev,
16241624
return -EIO;
16251625

16261626
if (stat)
1627-
return sprintf(buf, "spi\n");
1627+
return sysfs_emit(buf, "spi\n");
16281628

1629-
return sprintf(buf, "i2c\n");
1629+
return sysfs_emit(buf, "i2c\n");
16301630
}
16311631

16321632
static IIO_DEVICE_ATTR(bus_type, 0444, adt7316_show_bus_type, NULL, 0);
@@ -1836,7 +1836,7 @@ static ssize_t adt7316_show_int_mask(struct device *dev,
18361836
struct iio_dev *dev_info = dev_to_iio_dev(dev);
18371837
struct adt7316_chip_info *chip = iio_priv(dev_info);
18381838

1839-
return sprintf(buf, "0x%x\n", chip->int_mask);
1839+
return sysfs_emit(buf, "0x%x\n", chip->int_mask);
18401840
}
18411841

18421842
/*
@@ -1910,7 +1910,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
19101910
data -= 256;
19111911
}
19121912

1913-
return sprintf(buf, "%d\n", data);
1913+
return sysfs_emit(buf, "%d\n", data);
19141914
}
19151915

19161916
static inline ssize_t adt7316_set_ad_bound(struct device *dev,
@@ -1961,7 +1961,7 @@ static ssize_t adt7316_show_int_enabled(struct device *dev,
19611961
struct iio_dev *dev_info = dev_to_iio_dev(dev);
19621962
struct adt7316_chip_info *chip = iio_priv(dev_info);
19631963

1964-
return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_INT_EN));
1964+
return sysfs_emit(buf, "%d\n", !!(chip->config1 & ADT7316_INT_EN));
19651965
}
19661966

19671967
static ssize_t adt7316_set_int_enabled(struct device *dev,

0 commit comments

Comments
 (0)