if kstrdup() fails in kobject_set_name_varg() in dev_set_name(), the strchr() in kobject_add() of device_add() will cause null-ptr-deref below. So check the err of dev_set_name(). Fixes: a5e6e6505f38 ("sample: vfio bochs vbe display (host device for bochs-drm)") Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx> --- samples/vfio-mdev/mbochs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 3764d1911b51..b7f8518cd48a 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1430,7 +1430,9 @@ static int __init mbochs_dev_init(void) } mbochs_dev.class = mbochs_class; mbochs_dev.release = mbochs_device_release; - dev_set_name(&mbochs_dev, "%s", MBOCHS_NAME); + ret = dev_set_name(&mbochs_dev, "%s", MBOCHS_NAME); + if (ret) + goto err_put; ret = device_register(&mbochs_dev); if (ret) -- 2.34.1