2525#include <linux/module.h>
2626#include <linux/slab.h>
2727#include <linux/notifier.h>
28+ #include <linux/kobject.h>
2829#include <crypto/pcrypt.h>
2930
3031struct pcrypt_instance {
32+ const char * name ;
3133 struct padata_instance * pinst ;
3234 struct workqueue_struct * wq ;
3335
@@ -55,7 +57,7 @@ struct pcrypt_instance {
5557
5658static struct pcrypt_instance pencrypt ;
5759static struct pcrypt_instance pdecrypt ;
58-
60+ static struct kset * pcrypt_kset ;
5961
6062struct pcrypt_instance_ctx {
6163 struct crypto_spawn spawn ;
@@ -429,12 +431,25 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self,
429431 return 0 ;
430432}
431433
434+ static int pcrypt_sysfs_add (struct padata_instance * pinst , const char * name )
435+ {
436+ int ret ;
437+
438+ pinst -> kobj .kset = pcrypt_kset ;
439+ ret = kobject_add (& pinst -> kobj , NULL , name );
440+ if (!ret )
441+ kobject_uevent (& pinst -> kobj , KOBJ_ADD );
442+
443+ return ret ;
444+ }
445+
432446static int __pcrypt_init_instance (struct pcrypt_instance * pcrypt ,
433447 const char * name )
434448{
435449 int ret = - ENOMEM ;
436450 struct pcrypt_cpumask * mask ;
437451
452+ pcrypt -> name = name ;
438453 pcrypt -> wq = create_workqueue (name );
439454 if (!pcrypt -> wq )
440455 goto err ;
@@ -459,7 +474,13 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
459474 if (ret )
460475 goto err_free_cpumask ;
461476
477+ ret = pcrypt_sysfs_add (pcrypt -> pinst , name );
478+ if (ret )
479+ goto err_unregister_notifier ;
480+
462481 return ret ;
482+ err_unregister_notifier :
483+ padata_unregister_cpumask_notifier (pcrypt -> pinst , & pcrypt -> nblock );
463484err_free_cpumask :
464485 free_cpumask_var (mask -> mask );
465486 kfree (mask );
@@ -473,6 +494,7 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
473494
474495static void __pcrypt_deinit_instance (struct pcrypt_instance * pcrypt )
475496{
497+ kobject_put (& pcrypt -> pinst -> kobj );
476498 free_cpumask_var (pcrypt -> cb_cpumask -> mask );
477499 kfree (pcrypt -> cb_cpumask );
478500
@@ -491,11 +513,15 @@ static struct crypto_template pcrypt_tmpl = {
491513
492514static int __init pcrypt_init (void )
493515{
494- int err ;
516+ int err = - ENOMEM ;
517+
518+ pcrypt_kset = kset_create_and_add ("pcrypt" , NULL , kernel_kobj );
519+ if (!pcrypt_kset )
520+ goto err ;
495521
496522 err = __pcrypt_init_instance (& pencrypt , "pencrypt" );
497523 if (err )
498- goto err ;
524+ goto err_unreg_kset ;
499525
500526 err = __pcrypt_init_instance (& pdecrypt , "pdecrypt" );
501527 if (err )
@@ -508,6 +534,8 @@ static int __init pcrypt_init(void)
508534
509535err_deinit_pencrypt :
510536 __pcrypt_deinit_instance (& pencrypt );
537+ err_unreg_kset :
538+ kset_unregister (pcrypt_kset );
511539err :
512540 return err ;
513541}
@@ -517,6 +545,7 @@ static void __exit pcrypt_exit(void)
517545 __pcrypt_deinit_instance (& pencrypt );
518546 __pcrypt_deinit_instance (& pdecrypt );
519547
548+ kset_unregister (pcrypt_kset );
520549 crypto_unregister_template (& pcrypt_tmpl );
521550}
522551
0 commit comments