* drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
@ 2023-12-25 21:18 kernel test robot
0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2023-12-25 21:18 UTC (permalink / raw)
To: Eddie James; +Cc: oe-kbuild-all, linux-kernel, Guenter Roeck
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 861deac3b092f37b2c5e6871732f3e11486f7082
commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
date: 4 years, 4 months ago
config: x86_64-randconfig-x063-20230716 (https://download.01.org/0day-ci/archive/20231226/202312260533.FU092oo9-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260533.FU092oo9-lkp@intel.com/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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312260533.FU092oo9-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/hwmon/pmbus/ibm-cffps.c: In function 'ibm_cffps_debugfs_op':
drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:59: note: directive argument in the range [0, 2147483647]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:33: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Wformat-truncation=]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:59: note: directive argument in the range [0, 2147483647]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:33: note: 'snprintf' output between 5 and 9 bytes into a destination of size 5
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +184 drivers/hwmon/pmbus/ibm-cffps.c
129
130 static ssize_t ibm_cffps_debugfs_op(struct file *file, char __user *buf,
131 size_t count, loff_t *ppos)
132 {
133 u8 cmd;
134 int i, rc;
135 int *idxp = file->private_data;
136 int idx = *idxp;
137 struct ibm_cffps *psu = to_psu(idxp, idx);
138 char data[I2C_SMBUS_BLOCK_MAX] = { 0 };
139
140 pmbus_set_page(psu->client, 0);
141
142 switch (idx) {
143 case CFFPS_DEBUGFS_INPUT_HISTORY:
144 return ibm_cffps_read_input_history(psu, buf, count, ppos);
145 case CFFPS_DEBUGFS_FRU:
146 cmd = CFFPS_FRU_CMD;
147 break;
148 case CFFPS_DEBUGFS_PN:
149 cmd = CFFPS_PN_CMD;
150 break;
151 case CFFPS_DEBUGFS_SN:
152 cmd = CFFPS_SN_CMD;
153 break;
154 case CFFPS_DEBUGFS_CCIN:
155 rc = i2c_smbus_read_word_swapped(psu->client, CFFPS_CCIN_CMD);
156 if (rc < 0)
157 return rc;
158
159 rc = snprintf(data, 5, "%04X", rc);
160 goto done;
161 case CFFPS_DEBUGFS_FW:
162 switch (psu->version) {
163 case cffps1:
164 for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) {
165 rc = i2c_smbus_read_byte_data(psu->client,
166 CFFPS_FW_CMD +
167 i);
168 if (rc < 0)
169 return rc;
170
171 snprintf(&data[i * 2], 3, "%02X", rc);
172 }
173
174 rc = i * 2;
175 break;
176 case cffps2:
177 for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) {
178 rc = i2c_smbus_read_word_data(psu->client,
179 CFFPS_FW_CMD +
180 i);
181 if (rc < 0)
182 return rc;
183
> 184 snprintf(&data[i * 4], 5, "%04X", rc);
185 }
186
187 rc = i * 4;
188 break;
189 default:
190 return -EOPNOTSUPP;
191 }
192 goto done;
193 default:
194 return -EINVAL;
195 }
196
197 rc = i2c_smbus_read_block_data(psu->client, cmd, data);
198 if (rc < 0)
199 return rc;
200
201 done:
202 data[rc] = '\n';
203 rc += 2;
204
205 return simple_read_from_buffer(buf, count, ppos, data, rc);
206 }
207
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread* drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
@ 2024-01-25 3:52 kernel test robot
0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2024-01-25 3:52 UTC (permalink / raw)
To: Eddie James; +Cc: oe-kbuild-all, linux-kernel, Guenter Roeck
Hi Eddie,
FYI, the error/warning still remains.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 6098d87eaf31f48153c984e2adadf14762520a87
commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
date: 4 years, 5 months ago
config: x86_64-randconfig-006-20240105 (https://download.01.org/0day-ci/archive/20240125/202401251132.8DpJ7Stv-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240125/202401251132.8DpJ7Stv-lkp@intel.com/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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401251132.8DpJ7Stv-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/hwmon/pmbus/ibm-cffps.c: In function 'ibm_cffps_debugfs_op':
drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:59: note: directive argument in the range [0, 2147483647]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:33: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Wformat-truncation=]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:59: note: directive argument in the range [0, 2147483647]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:33: note: 'snprintf' output between 5 and 9 bytes into a destination of size 5
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +184 drivers/hwmon/pmbus/ibm-cffps.c
129
130 static ssize_t ibm_cffps_debugfs_op(struct file *file, char __user *buf,
131 size_t count, loff_t *ppos)
132 {
133 u8 cmd;
134 int i, rc;
135 int *idxp = file->private_data;
136 int idx = *idxp;
137 struct ibm_cffps *psu = to_psu(idxp, idx);
138 char data[I2C_SMBUS_BLOCK_MAX] = { 0 };
139
140 pmbus_set_page(psu->client, 0);
141
142 switch (idx) {
143 case CFFPS_DEBUGFS_INPUT_HISTORY:
144 return ibm_cffps_read_input_history(psu, buf, count, ppos);
145 case CFFPS_DEBUGFS_FRU:
146 cmd = CFFPS_FRU_CMD;
147 break;
148 case CFFPS_DEBUGFS_PN:
149 cmd = CFFPS_PN_CMD;
150 break;
151 case CFFPS_DEBUGFS_SN:
152 cmd = CFFPS_SN_CMD;
153 break;
154 case CFFPS_DEBUGFS_CCIN:
155 rc = i2c_smbus_read_word_swapped(psu->client, CFFPS_CCIN_CMD);
156 if (rc < 0)
157 return rc;
158
159 rc = snprintf(data, 5, "%04X", rc);
160 goto done;
161 case CFFPS_DEBUGFS_FW:
162 switch (psu->version) {
163 case cffps1:
164 for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) {
165 rc = i2c_smbus_read_byte_data(psu->client,
166 CFFPS_FW_CMD +
167 i);
168 if (rc < 0)
169 return rc;
170
171 snprintf(&data[i * 2], 3, "%02X", rc);
172 }
173
174 rc = i * 2;
175 break;
176 case cffps2:
177 for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) {
178 rc = i2c_smbus_read_word_data(psu->client,
179 CFFPS_FW_CMD +
180 i);
181 if (rc < 0)
182 return rc;
183
> 184 snprintf(&data[i * 4], 5, "%04X", rc);
185 }
186
187 rc = i * 4;
188 break;
189 default:
190 return -EOPNOTSUPP;
191 }
192 goto done;
193 default:
194 return -EINVAL;
195 }
196
197 rc = i2c_smbus_read_block_data(psu->client, cmd, data);
198 if (rc < 0)
199 return rc;
200
201 done:
202 data[rc] = '\n';
203 rc += 2;
204
205 return simple_read_from_buffer(buf, count, ppos, data, rc);
206 }
207
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread* drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
@ 2024-12-20 13:54 kernel test robot
2024-12-20 15:21 ` Guenter Roeck
0 siblings, 1 reply; 8+ messages in thread
From: kernel test robot @ 2024-12-20 13:54 UTC (permalink / raw)
To: Eddie James; +Cc: oe-kbuild-all, linux-kernel, Guenter Roeck
Hi Eddie,
FYI, the error/warning still remains.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 8faabc041a001140564f718dabe37753e88b37fa
commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
date: 5 years ago
config: x86_64-randconfig-077-20241209 (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412202139.tZ2VJL2f-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/hwmon/pmbus/ibm-cffps.c: In function 'ibm_cffps_debugfs_op':
drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:59: note: directive argument in the range [0, 2147483647]
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:171:33: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
171 | snprintf(&data[i * 2], 3, "%02X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Wformat-truncation=]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:59: note: directive argument in the range [0, 2147483647]
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~
drivers/hwmon/pmbus/ibm-cffps.c:184:33: note: 'snprintf' output between 5 and 9 bytes into a destination of size 5
184 | snprintf(&data[i * 4], 5, "%04X", rc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +184 drivers/hwmon/pmbus/ibm-cffps.c
129
130 static ssize_t ibm_cffps_debugfs_op(struct file *file, char __user *buf,
131 size_t count, loff_t *ppos)
132 {
133 u8 cmd;
134 int i, rc;
135 int *idxp = file->private_data;
136 int idx = *idxp;
137 struct ibm_cffps *psu = to_psu(idxp, idx);
138 char data[I2C_SMBUS_BLOCK_MAX] = { 0 };
139
140 pmbus_set_page(psu->client, 0);
141
142 switch (idx) {
143 case CFFPS_DEBUGFS_INPUT_HISTORY:
144 return ibm_cffps_read_input_history(psu, buf, count, ppos);
145 case CFFPS_DEBUGFS_FRU:
146 cmd = CFFPS_FRU_CMD;
147 break;
148 case CFFPS_DEBUGFS_PN:
149 cmd = CFFPS_PN_CMD;
150 break;
151 case CFFPS_DEBUGFS_SN:
152 cmd = CFFPS_SN_CMD;
153 break;
154 case CFFPS_DEBUGFS_CCIN:
155 rc = i2c_smbus_read_word_swapped(psu->client, CFFPS_CCIN_CMD);
156 if (rc < 0)
157 return rc;
158
159 rc = snprintf(data, 5, "%04X", rc);
160 goto done;
161 case CFFPS_DEBUGFS_FW:
162 switch (psu->version) {
163 case cffps1:
164 for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) {
165 rc = i2c_smbus_read_byte_data(psu->client,
166 CFFPS_FW_CMD +
167 i);
168 if (rc < 0)
169 return rc;
170
171 snprintf(&data[i * 2], 3, "%02X", rc);
172 }
173
174 rc = i * 2;
175 break;
176 case cffps2:
177 for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) {
178 rc = i2c_smbus_read_word_data(psu->client,
179 CFFPS_FW_CMD +
180 i);
181 if (rc < 0)
182 return rc;
183
> 184 snprintf(&data[i * 4], 5, "%04X", rc);
185 }
186
187 rc = i * 4;
188 break;
189 default:
190 return -EOPNOTSUPP;
191 }
192 goto done;
193 default:
194 return -EINVAL;
195 }
196
197 rc = i2c_smbus_read_block_data(psu->client, cmd, data);
198 if (rc < 0)
199 return rc;
200
201 done:
202 data[rc] = '\n';
203 rc += 2;
204
205 return simple_read_from_buffer(buf, count, ppos, data, rc);
206 }
207
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
2024-12-20 13:54 kernel test robot
@ 2024-12-20 15:21 ` Guenter Roeck
2024-12-20 16:30 ` David Laight
0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2024-12-20 15:21 UTC (permalink / raw)
To: kernel test robot, Eddie James; +Cc: oe-kbuild-all, linux-kernel
On 12/20/24 05:54, kernel test robot wrote:
> Hi Eddie,
>
> FYI, the error/warning still remains.
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 8faabc041a001140564f718dabe37753e88b37fa
> commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
> date: 5 years ago
> config: x86_64-randconfig-077-20241209 (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/config)
> compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/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@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202412202139.tZ2VJL2f-lkp@intel.com/
>
We could use %2. 2X and %4.4X to make the compiler happy, but those are false positives.
rc is known in all cases to not exceed the format size. I don't see the point of changing
the code just to make the compiler happy.
Guenter
> All warnings (new ones prefixed by >>):
>
> drivers/hwmon/pmbus/ibm-cffps.c: In function 'ibm_cffps_debugfs_op':
> drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
> | ^~~~
> drivers/hwmon/pmbus/ibm-cffps.c:171:59: note: directive argument in the range [0, 2147483647]
> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
> | ^~~~~~
> drivers/hwmon/pmbus/ibm-cffps.c:171:33: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Wformat-truncation=]
> 184 | snprintf(&data[i * 4], 5, "%04X", rc);
> | ^~~~
> drivers/hwmon/pmbus/ibm-cffps.c:184:59: note: directive argument in the range [0, 2147483647]
> 184 | snprintf(&data[i * 4], 5, "%04X", rc);
> | ^~~~~~
> drivers/hwmon/pmbus/ibm-cffps.c:184:33: note: 'snprintf' output between 5 and 9 bytes into a destination of size 5
> 184 | snprintf(&data[i * 4], 5, "%04X", rc);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> vim +184 drivers/hwmon/pmbus/ibm-cffps.c
>
> 129
> 130 static ssize_t ibm_cffps_debugfs_op(struct file *file, char __user *buf,
> 131 size_t count, loff_t *ppos)
> 132 {
> 133 u8 cmd;
> 134 int i, rc;
> 135 int *idxp = file->private_data;
> 136 int idx = *idxp;
> 137 struct ibm_cffps *psu = to_psu(idxp, idx);
> 138 char data[I2C_SMBUS_BLOCK_MAX] = { 0 };
> 139
> 140 pmbus_set_page(psu->client, 0);
> 141
> 142 switch (idx) {
> 143 case CFFPS_DEBUGFS_INPUT_HISTORY:
> 144 return ibm_cffps_read_input_history(psu, buf, count, ppos);
> 145 case CFFPS_DEBUGFS_FRU:
> 146 cmd = CFFPS_FRU_CMD;
> 147 break;
> 148 case CFFPS_DEBUGFS_PN:
> 149 cmd = CFFPS_PN_CMD;
> 150 break;
> 151 case CFFPS_DEBUGFS_SN:
> 152 cmd = CFFPS_SN_CMD;
> 153 break;
> 154 case CFFPS_DEBUGFS_CCIN:
> 155 rc = i2c_smbus_read_word_swapped(psu->client, CFFPS_CCIN_CMD);
> 156 if (rc < 0)
> 157 return rc;
> 158
> 159 rc = snprintf(data, 5, "%04X", rc);
> 160 goto done;
> 161 case CFFPS_DEBUGFS_FW:
> 162 switch (psu->version) {
> 163 case cffps1:
> 164 for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) {
> 165 rc = i2c_smbus_read_byte_data(psu->client,
> 166 CFFPS_FW_CMD +
> 167 i);
> 168 if (rc < 0)
> 169 return rc;
> 170
> 171 snprintf(&data[i * 2], 3, "%02X", rc);
> 172 }
> 173
> 174 rc = i * 2;
> 175 break;
> 176 case cffps2:
> 177 for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) {
> 178 rc = i2c_smbus_read_word_data(psu->client,
> 179 CFFPS_FW_CMD +
> 180 i);
> 181 if (rc < 0)
> 182 return rc;
> 183
> > 184 snprintf(&data[i * 4], 5, "%04X", rc);
> 185 }
> 186
> 187 rc = i * 4;
> 188 break;
> 189 default:
> 190 return -EOPNOTSUPP;
> 191 }
> 192 goto done;
> 193 default:
> 194 return -EINVAL;
> 195 }
> 196
> 197 rc = i2c_smbus_read_block_data(psu->client, cmd, data);
> 198 if (rc < 0)
> 199 return rc;
> 200
> 201 done:
> 202 data[rc] = '\n';
> 203 rc += 2;
> 204
> 205 return simple_read_from_buffer(buf, count, ppos, data, rc);
> 206 }
> 207
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
2024-12-20 15:21 ` Guenter Roeck
@ 2024-12-20 16:30 ` David Laight
2024-12-20 17:03 ` Guenter Roeck
0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2024-12-20 16:30 UTC (permalink / raw)
To: Guenter Roeck; +Cc: kernel test robot, Eddie James, oe-kbuild-all, linux-kernel
On Fri, 20 Dec 2024 07:21:18 -0800
Guenter Roeck <linux@roeck-us.net> wrote:
> On 12/20/24 05:54, kernel test robot wrote:
> > Hi Eddie,
> >
> > FYI, the error/warning still remains.
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 8faabc041a001140564f718dabe37753e88b37fa
> > commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
> > date: 5 years ago
> > config: x86_64-randconfig-077-20241209 (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/config)
> > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/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@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202412202139.tZ2VJL2f-lkp@intel.com/
> >
>
> We could use %2. 2X and %4.4X to make the compiler happy, but those are false positives.
> rc is known in all cases to not exceed the format size. I don't see the point of changing
> the code just to make the compiler happy.
I doubt they'd make any difference.
>
> > drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
> > 171 | snprintf(&data[i * 2], 3, "%02X", rc);
The only ways I know are to bound check the value or to use
OPTIMISER_HIDE_VAR() on the length.
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
2024-12-20 16:30 ` David Laight
@ 2024-12-20 17:03 ` Guenter Roeck
2024-12-20 17:29 ` David Laight
0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2024-12-20 17:03 UTC (permalink / raw)
To: David Laight; +Cc: kernel test robot, Eddie James, oe-kbuild-all, linux-kernel
On 12/20/24 08:30, David Laight wrote:
> On Fri, 20 Dec 2024 07:21:18 -0800
> Guenter Roeck <linux@roeck-us.net> wrote:
>
>> On 12/20/24 05:54, kernel test robot wrote:
>>> Hi Eddie,
>>>
>>> FYI, the error/warning still remains.
>>>
>>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>>> head: 8faabc041a001140564f718dabe37753e88b37fa
>>> commit: 2f8a855efe8a6faf962c53af406e5ea4791b3877 pmbus: (ibm-cffps) Add support for version 2 of the PSU
>>> date: 5 years ago
>>> config: x86_64-randconfig-077-20241209 (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/config)
>>> compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
>>> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241220/202412202139.tZ2VJL2f-lkp@intel.com/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@intel.com>
>>> | Closes: https://lore.kernel.org/oe-kbuild-all/202412202139.tZ2VJL2f-lkp@intel.com/
>>>
>>
>> We could use %2. 2X and %4.4X to make the compiler happy, but those are false positives.
>> rc is known in all cases to not exceed the format size. I don't see the point of changing
>> the code just to make the compiler happy.
>
> I doubt they'd make any difference.
>
Yes, you are correct.
>>
>>> drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
>>> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
>
> The only ways I know are to bound check the value or to use
> OPTIMISER_HIDE_VAR() on the length.
>
- snprintf(&data[i * 2], 3, "%02X", rc);
+ snprintf(&data[i * 2], 3, "%02X", rc & 0xff);
works as well, at least with gcc 11 and 12, but I really dislike that kind of nonsense.
Guenter
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
2024-12-20 17:03 ` Guenter Roeck
@ 2024-12-20 17:29 ` David Laight
2024-12-20 17:56 ` Guenter Roeck
0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2024-12-20 17:29 UTC (permalink / raw)
To: Guenter Roeck; +Cc: kernel test robot, Eddie James, oe-kbuild-all, linux-kernel
On Fri, 20 Dec 2024 09:03:51 -0800
Guenter Roeck <linux@roeck-us.net> wrote:
> On 12/20/24 08:30, David Laight wrote:
...
> >>
> >>> drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
> >>> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
> >
> > The only ways I know are to bound check the value or to use
> > OPTIMISER_HIDE_VAR() on the length.
> >
>
> - snprintf(&data[i * 2], 3, "%02X", rc);
> + snprintf(&data[i * 2], 3, "%02X", rc & 0xff);
>
> works as well, at least with gcc 11 and 12, but I really dislike that kind of nonsense.
Ditto.
Using the result in some ways can also remove the warning.
But you have to try quite hard, a simple (void) really ought to be
enough to show you 'just don't care' but even 'if (snprintf(...)) {}'
isn't enough (it does silence 'warn-unused-result').
I mean, the whole point of snprintf() is that it truncates.
David
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5
2024-12-20 17:29 ` David Laight
@ 2024-12-20 17:56 ` Guenter Roeck
0 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2024-12-20 17:56 UTC (permalink / raw)
To: David Laight; +Cc: kernel test robot, Eddie James, oe-kbuild-all, linux-kernel
On 12/20/24 09:29, David Laight wrote:
> On Fri, 20 Dec 2024 09:03:51 -0800
> Guenter Roeck <linux@roeck-us.net> wrote:
>
>> On 12/20/24 08:30, David Laight wrote:
> ...
>>>>
>>>>> drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
>>>>> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
>>>
>>> The only ways I know are to bound check the value or to use
>>> OPTIMISER_HIDE_VAR() on the length.
Actually, that doesn't work.
- snprintf(&data[i * 2], 3, "%02X", rc);
+ snprintf(&data[i * 2], OPTIMIZER_HIDE_VAR(3), "%02X", rc);
triggers:
drivers/hwmon/pmbus/ibm-cffps.c: In function ‘ibm_cffps_debugfs_read’:
./include/linux/compiler.h:186:9: error: expected expression before ‘__asm__’
>>>
>>
>> - snprintf(&data[i * 2], 3, "%02X", rc);
>> + snprintf(&data[i * 2], 3, "%02X", rc & 0xff);
>>
>> works as well, at least with gcc 11 and 12, but I really dislike that kind of nonsense.
>
> Ditto.
> Using the result in some ways can also remove the warning.
> But you have to try quite hard, a simple (void) really ought to be
> enough to show you 'just don't care' but even 'if (snprintf(...)) {}'
> isn't enough (it does silence 'warn-unused-result').
>
> I mean, the whole point of snprintf() is that it truncates.
>
Using scnprintf() "fixes" the problem as well, but there are other patches
suggesting that snprintf() should be used if the return value is not
needed/checked because it is slightly simpler.
Guenter
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-12-20 17:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-25 21:18 drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size 5 kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2024-01-25 3:52 kernel test robot
2024-12-20 13:54 kernel test robot
2024-12-20 15:21 ` Guenter Roeck
2024-12-20 16:30 ` David Laight
2024-12-20 17:03 ` Guenter Roeck
2024-12-20 17:29 ` David Laight
2024-12-20 17:56 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox