Skip to content

Commit bdc7750

Browse files
committed
um: virt-pci: Avoid GCC non-NULL warning
GCC gets confused about the return value of get_cpu_var() possibly being NULL, so explicitly test for it before calls to memcpy() and memset(). Avoids warnings like this: arch/um/drivers/virt-pci.c: In function 'um_pci_send_cmd': include/linux/fortify-string.h:48:33: warning: argument 1 null where non-null expected [-Wnonnull] 48 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:438:9: note: in expansion of macro '__underlying_memcpy' 438 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ include/linux/fortify-string.h:483:26: note: in expansion of macro '__fortify_memcpy_chk' 483 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ arch/um/drivers/virt-pci.c:100:9: note: in expansion of macro 'memcpy' 100 | memcpy(buf, cmd, cmd_size); | ^~~~~~ While at it, avoid literal "8" and use stored sizeof(buf->data) in memset() and um_pci_send_cmd(). Reported-by: kernel test robot <[email protected]> Link: https://lore.kernel.org/lkml/[email protected] Fixes: ba38961 ("um: Enable FORTIFY_SOURCE") Cc: Richard Weinberger <[email protected]> Cc: Anton Ivanov <[email protected]> Cc: Johannes Berg <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Al Viro <[email protected]> Cc: Xiu Jianfeng <[email protected]> Cc: Vincent Whitchurch <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 3a017d6 commit bdc7750

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/um/drivers/virt-pci.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static int um_pci_send_cmd(struct um_pci_device *dev,
9797
}
9898

9999
buf = get_cpu_var(um_pci_msg_bufs);
100-
memcpy(buf, cmd, cmd_size);
100+
if (buf)
101+
memcpy(buf, cmd, cmd_size);
101102

102103
if (posted) {
103104
u8 *ncmd = kmalloc(cmd_size + extra_size, GFP_ATOMIC);
@@ -182,14 +183,16 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,
182183
struct um_pci_message_buffer *buf;
183184
u8 *data;
184185
unsigned long ret = ULONG_MAX;
186+
size_t bytes = sizeof(buf->data);
185187

186188
if (!dev)
187189
return ULONG_MAX;
188190

189191
buf = get_cpu_var(um_pci_msg_bufs);
190192
data = buf->data;
191193

192-
memset(buf->data, 0xff, sizeof(buf->data));
194+
if (buf)
195+
memset(data, 0xff, bytes);
193196

194197
switch (size) {
195198
case 1:
@@ -204,7 +207,7 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,
204207
goto out;
205208
}
206209

207-
if (um_pci_send_cmd(dev, &hdr, sizeof(hdr), NULL, 0, data, 8))
210+
if (um_pci_send_cmd(dev, &hdr, sizeof(hdr), NULL, 0, data, bytes))
208211
goto out;
209212

210213
switch (size) {

0 commit comments

Comments
 (0)