diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
index d0c687fd9802220bd558303f54ccd683e77a3803..5dce351f131f8c154048124bc1bf3a6a32cb32c7 100644
--- a/samples/kobject/kset-example.c
+++ b/samples/kobject/kset-example.c
@@ -262,6 +262,7 @@ static int __init example_init(void)
 bar_error:
 	destroy_foo_obj(foo_obj);
 foo_error:
+	kset_unregister(example_kset);
 	return -EINVAL;
 }