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

Revert "virtio-console: remove unnecessary kmemdup()"

This reverts commit 9db81eca10ba2d84177fa076704db3a5d76863c3.

A dependant patch on this one needs to be reverted, so this one also
needs to be reverted at this point in time.

Link: https://lore.kernel.org/r/208f7a41-a9fa-630c-cb44-c37c503f3a72@kernel.org
Reported-by: Jiri Slaby <jirislaby@kernel.org>
Cc: Xianting Tian <xianting.tian@linux.alibaba.com>
Cc: Shile Zhang <shile.zhang@linux.alibaba.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+10 -2
+10 -2
drivers/char/virtio_console.c
··· 1117 1117 { 1118 1118 struct port *port; 1119 1119 struct scatterlist sg[1]; 1120 + void *data; 1121 + int ret; 1120 1122 1121 1123 if (unlikely(early_put_chars)) 1122 1124 return early_put_chars(vtermno, buf, count); ··· 1127 1125 if (!port) 1128 1126 return -EPIPE; 1129 1127 1130 - sg_init_one(sg, buf, count); 1131 - return __send_to_port(port, sg, 1, count, (void *)buf, false); 1128 + data = kmemdup(buf, count, GFP_ATOMIC); 1129 + if (!data) 1130 + return -ENOMEM; 1131 + 1132 + sg_init_one(sg, data, count); 1133 + ret = __send_to_port(port, sg, 1, count, data, false); 1134 + kfree(data); 1135 + return ret; 1132 1136 } 1133 1137 1134 1138 /*