drivers/hwmon/scpi-hwmon.c:115:19: warning: 'snprintf' output may be truncated before the last format character
From: kernel test robot
Date: Sun Oct 13 2024 - 00:44:48 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 36c254515dc6592c44db77b84908358979dd6b50
commit: ea98b29a05e9c70dbe159cbc6254d111059a2bb9 hwmon: Support sensors exported via ARM SCP interface
date: 9 years ago
config: arm64-randconfig-004-20241013 (https://download.01.org/0day-ci/archive/20241013/202410131210.VThsB2aJ-lkp@xxxxxxxxx/config)
compiler: aarch64-linux-gcc (GCC) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241013/202410131210.VThsB2aJ-lkp@xxxxxxxxx/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410131210.VThsB2aJ-lkp@xxxxxxxxx/
All warnings (new ones prefixed by >>):
In file included from arch/arm64/include/asm/bug.h:62:0,
from include/linux/bug.h:4,
from include/linux/thread_info.h:11,
from include/asm-generic/preempt.h:4,
from arch/arm64/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:64,
from include/linux/spinlock.h:50,
from include/linux/seqlock.h:35,
from include/linux/time.h:5,
from include/linux/stat.h:18,
from include/linux/module.h:10,
from drivers/hwmon/scpi-hwmon.c:18:
include/linux/gfp.h: In function 'gfp_zone':
include/asm-generic/bug.h:145:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
#define BUG_ON(condition) do { if (condition) ; } while (0)
^
include/linux/mmdebug.h:17:25: note: in expansion of macro 'BUG_ON'
#define VM_BUG_ON(cond) BUG_ON(cond)
^~~~~~
include/linux/gfp.h:255:2: note: in expansion of macro 'VM_BUG_ON'
VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
^~~~~~~~~
include/linux/gfp.h: In function '__alloc_pages_node':
include/asm-generic/bug.h:145:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
#define BUG_ON(condition) do { if (condition) ; } while (0)
^
include/linux/mmdebug.h:17:25: note: in expansion of macro 'BUG_ON'
#define VM_BUG_ON(cond) BUG_ON(cond)
^~~~~~
include/linux/gfp.h:313:2: note: in expansion of macro 'VM_BUG_ON'
VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES);
^~~~~~~~~
include/linux/seq_file.h: In function 'seq_get_buf':
include/asm-generic/bug.h:145:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
#define BUG_ON(condition) do { if (condition) ; } while (0)
^
include/linux/seq_file.h:70:2: note: in expansion of macro 'BUG_ON'
BUG_ON(m->count > m->size);
^~~~~~
include/linux/seq_file.h: In function 'seq_commit':
include/asm-generic/bug.h:145:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
#define BUG_ON(condition) do { if (condition) ; } while (0)
^
include/linux/seq_file.h:93:3: note: in expansion of macro 'BUG_ON'
BUG_ON(m->count + num > m->size);
^~~~~~
drivers/hwmon/scpi-hwmon.c: In function 'scpi_hwmon_probe':
>> drivers/hwmon/scpi-hwmon.c:115:19: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
"temp%d_input", num_temp + 1);
^
drivers/hwmon/scpi-hwmon.c:114:4: note: 'snprintf' output between 12 and 21 bytes into a destination of size 20
snprintf(sensor->input, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"temp%d_input", num_temp + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/hwmon/scpi-hwmon.c:117:19: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
"temp%d_label", num_temp + 1);
^
drivers/hwmon/scpi-hwmon.c:116:4: note: 'snprintf' output between 12 and 21 bytes into a destination of size 20
snprintf(sensor->label, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"temp%d_label", num_temp + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/hwmon/scpi-hwmon.c:129:19: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
"curr%d_input", num_current + 1);
^
drivers/hwmon/scpi-hwmon.c:128:4: note: 'snprintf' output between 12 and 21 bytes into a destination of size 20
snprintf(sensor->input, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"curr%d_input", num_current + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/hwmon/scpi-hwmon.c:131:19: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
"curr%d_label", num_current + 1);
^
drivers/hwmon/scpi-hwmon.c:130:4: note: 'snprintf' output between 12 and 21 bytes into a destination of size 20
snprintf(sensor->label, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"curr%d_label", num_current + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/scpi-hwmon.c:136:14: warning: '_input' directive output may be truncated writing 6 bytes into a region of size between 5 and 14 [-Wformat-truncation=]
"power%d_input", num_power + 1);
^~~~~~
drivers/hwmon/scpi-hwmon.c:135:4: note: 'snprintf' output between 13 and 22 bytes into a destination of size 20
snprintf(sensor->input, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"power%d_input", num_power + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/scpi-hwmon.c:138:14: warning: '_label' directive output may be truncated writing 6 bytes into a region of size between 5 and 14 [-Wformat-truncation=]
"power%d_label", num_power + 1);
^~~~~~
drivers/hwmon/scpi-hwmon.c:137:4: note: 'snprintf' output between 13 and 22 bytes into a destination of size 20
snprintf(sensor->label, sizeof(sensor->input),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"power%d_label", num_power + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/snprintf +115 drivers/hwmon/scpi-hwmon.c
68
69 static int scpi_hwmon_probe(struct platform_device *pdev)
70 {
71 u16 nr_sensors, i;
72 int num_temp = 0, num_volt = 0, num_current = 0, num_power = 0;
73 struct scpi_ops *scpi_ops;
74 struct device *hwdev, *dev = &pdev->dev;
75 struct scpi_sensors *scpi_sensors;
76 int ret;
77
78 scpi_ops = get_scpi_ops();
79 if (!scpi_ops)
80 return -EPROBE_DEFER;
81
82 ret = scpi_ops->sensor_get_capability(&nr_sensors);
83 if (ret)
84 return ret;
85
86 if (!nr_sensors)
87 return -ENODEV;
88
89 scpi_sensors = devm_kzalloc(dev, sizeof(*scpi_sensors), GFP_KERNEL);
90 if (!scpi_sensors)
91 return -ENOMEM;
92
93 scpi_sensors->data = devm_kcalloc(dev, nr_sensors,
94 sizeof(*scpi_sensors->data), GFP_KERNEL);
95 if (!scpi_sensors->data)
96 return -ENOMEM;
97
98 scpi_sensors->attrs = devm_kcalloc(dev, (nr_sensors * 2) + 1,
99 sizeof(*scpi_sensors->attrs), GFP_KERNEL);
100 if (!scpi_sensors->attrs)
101 return -ENOMEM;
102
103 scpi_sensors->scpi_ops = scpi_ops;
104
105 for (i = 0; i < nr_sensors; i++) {
106 struct sensor_data *sensor = &scpi_sensors->data[i];
107
108 ret = scpi_ops->sensor_get_info(i, &sensor->info);
109 if (ret)
110 return ret;
111
112 switch (sensor->info.class) {
113 case TEMPERATURE:
114 snprintf(sensor->input, sizeof(sensor->input),
> 115 "temp%d_input", num_temp + 1);
116 snprintf(sensor->label, sizeof(sensor->input),
117 "temp%d_label", num_temp + 1);
118 num_temp++;
119 break;
120 case VOLTAGE:
121 snprintf(sensor->input, sizeof(sensor->input),
122 "in%d_input", num_volt);
123 snprintf(sensor->label, sizeof(sensor->input),
124 "in%d_label", num_volt);
125 num_volt++;
126 break;
127 case CURRENT:
128 snprintf(sensor->input, sizeof(sensor->input),
129 "curr%d_input", num_current + 1);
130 snprintf(sensor->label, sizeof(sensor->input),
> 131 "curr%d_label", num_current + 1);
132 num_current++;
133 break;
134 case POWER:
135 snprintf(sensor->input, sizeof(sensor->input),
> 136 "power%d_input", num_power + 1);
137 snprintf(sensor->label, sizeof(sensor->input),
> 138 "power%d_label", num_power + 1);
139 num_power++;
140 break;
141 default:
142 break;
143 }
144
145 sensor->dev_attr_input.attr.mode = S_IRUGO;
146 sensor->dev_attr_input.show = scpi_show_sensor;
147 sensor->dev_attr_input.attr.name = sensor->input;
148
149 sensor->dev_attr_label.attr.mode = S_IRUGO;
150 sensor->dev_attr_label.show = scpi_show_label;
151 sensor->dev_attr_label.attr.name = sensor->label;
152
153 scpi_sensors->attrs[i << 1] = &sensor->dev_attr_input.attr;
154 scpi_sensors->attrs[(i << 1) + 1] = &sensor->dev_attr_label.attr;
155
156 sysfs_attr_init(scpi_sensors->attrs[i << 1]);
157 sysfs_attr_init(scpi_sensors->attrs[(i << 1) + 1]);
158 }
159
160 scpi_sensors->group.attrs = scpi_sensors->attrs;
161 scpi_sensors->groups[0] = &scpi_sensors->group;
162
163 hwdev = devm_hwmon_device_register_with_groups(dev,
164 "scpi_sensors", scpi_sensors, scpi_sensors->groups);
165
166 return PTR_ERR_OR_ZERO(hwdev);
167 }
168
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki