Skip to content

Commit a3fb1e3

Browse files
Dan Kruchininherbertx
authored andcommitted
pcrypt: Added sysfs interface to pcrypt
Added sysfs interface to pcrypt. Now pcrypt subsystem creates two sysfs directories with corresponding padata sysfs objects: /sys/kernel/pcrypt/[pencrypt|pdecrypt] Signed-off-by: Dan Kruchinin <dkruchinin@acm.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5e017dc commit a3fb1e3

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

‎crypto/pcrypt.c‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
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

3031
struct 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

5658
static struct pcrypt_instance pencrypt;
5759
static struct pcrypt_instance pdecrypt;
58-
60+
static struct kset *pcrypt_kset;
5961

6062
struct 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+
432446
static 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);
463484
err_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

474495
static 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

492514
static 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

509535
err_deinit_pencrypt:
510536
__pcrypt_deinit_instance(&pencrypt);
537+
err_unreg_kset:
538+
kset_unregister(pcrypt_kset);
511539
err:
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

Comments
 (0)