[PATCH] powerpc: vas-api: constify dynamic struct class in coproc api register

Jori Koolstra posted 1 patch 1 month ago
There is a newer version of this series
arch/powerpc/platforms/book3s/vas-api.c     | 34 ++++++++++++++++-----
arch/powerpc/platforms/powernv/vas-window.c |  1 -
2 files changed, 26 insertions(+), 9 deletions(-)
[PATCH] powerpc: vas-api: constify dynamic struct class in coproc api register
Posted by Jori Koolstra 1 month ago
The class_create() call has been deprecated in favor of class_register()
as the driver core now allows for a struct class to be in read-only
memory.

In vas_register_coproc_api() the dynamic allocation of the struct class
corresonding to the coprocessor type (right now only nx-gzip) is
replaced by calling

	static const struct class* cop_to_class(enum vas_cop_type cop)

which links the coprocessor type to the appropriate static const struct
class.

Compile tested only.

Link: https://lore.kernel.org/all/2023040244-duffel-pushpin-f738@gregkh/

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
---
 arch/powerpc/platforms/book3s/vas-api.c     | 34 ++++++++++++++++-----
 arch/powerpc/platforms/powernv/vas-window.c |  1 -
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platforms/book3s/vas-api.c
index ea4ffa63f043..e377981fd533 100644
--- a/arch/powerpc/platforms/book3s/vas-api.c
+++ b/arch/powerpc/platforms/book3s/vas-api.c
@@ -45,7 +45,7 @@ static struct coproc_dev {
 	struct device *device;
 	char *name;
 	dev_t devt;
-	struct class *class;
+	const struct class *class;
 	enum vas_cop_type cop_type;
 	const struct vas_user_win_ops *vops;
 } coproc_device;
@@ -599,6 +599,21 @@ static struct file_operations coproc_fops = {
 	.unlocked_ioctl = coproc_ioctl,
 };
 
+static const struct class nx_gzip_class = {
+	.name		= "nx-gzip",
+	.devnode	= coproc_devnode
+};
+
+static const struct class* cop_to_class(enum vas_cop_type cop)
+{
+	switch (cop) {
+	case VAS_COP_TYPE_GZIP:		return &nx_gzip_class;
+	default:
+		pr_err("No device class defined for cop type %d\n", cop);
+		return NULL;
+	}
+}
+
 /*
  * Supporting only nx-gzip coprocessor type now, but this API code
  * extended to other coprocessor types later.
@@ -609,6 +624,10 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
 {
 	int rc = -EINVAL;
 	dev_t devno;
+	const struct class* class = cop_to_class(cop_type);
+
+	if (!class)
+		return rc;
 
 	rc = alloc_chrdev_region(&coproc_device.devt, 1, 1, name);
 	if (rc) {
@@ -619,13 +638,12 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
 	pr_devel("%s device allocated, dev [%i,%i]\n", name,
 			MAJOR(coproc_device.devt), MINOR(coproc_device.devt));
 
-	coproc_device.class = class_create(name);
-	if (IS_ERR(coproc_device.class)) {
-		rc = PTR_ERR(coproc_device.class);
-		pr_err("Unable to create %s class %d\n", name, rc);
+	rc = class_register(class);
+	if (rc) {
+		pr_err("Unable to register %s class %d\n", name, rc);
 		goto err_class;
 	}
-	coproc_device.class->devnode = coproc_devnode;
+	coproc_device.class = class;
 	coproc_device.cop_type = cop_type;
 	coproc_device.vops = vops;
 
@@ -654,7 +672,7 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
 err:
 	cdev_del(&coproc_device.cdev);
 err_cdev:
-	class_destroy(coproc_device.class);
+	class_unregister(coproc_device.class);
 err_class:
 	unregister_chrdev_region(coproc_device.devt, 1);
 	return rc;
@@ -668,6 +686,6 @@ void vas_unregister_coproc_api(void)
 	devno = MKDEV(MAJOR(coproc_device.devt), 0);
 	device_destroy(coproc_device.class, devno);
 
-	class_destroy(coproc_device.class);
+	class_unregister(coproc_device.class);
 	unregister_chrdev_region(coproc_device.devt, 1);
 }
diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index 9f093176b8db..34403582c895 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -1459,7 +1459,6 @@ static const struct vas_user_win_ops vops =  {
 int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
 			     const char *name)
 {
-
 	return vas_register_coproc_api(mod, cop_type, name, &vops);
 }
 EXPORT_SYMBOL_GPL(vas_register_api_powernv);

base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
-- 
2.53.0
Re: [PATCH] powerpc: vas-api: constify dynamic struct class in coproc api register
Posted by Greg KH 1 month ago
On Sun, Mar 08, 2026 at 01:39:12PM +0100, Jori Koolstra wrote:
> diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
> index 9f093176b8db..34403582c895 100644
> --- a/arch/powerpc/platforms/powernv/vas-window.c
> +++ b/arch/powerpc/platforms/powernv/vas-window.c
> @@ -1459,7 +1459,6 @@ static const struct vas_user_win_ops vops =  {
>  int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
>  			     const char *name)
>  {
> -
>  	return vas_register_coproc_api(mod, cop_type, name, &vops);
>  }
>  EXPORT_SYMBOL_GPL(vas_register_api_powernv);
> 

This change wasn't needed here :(

thanks,

greg k-h
Re: [PATCH] powerpc: vas-api: constify dynamic struct class in coproc api register
Posted by Jori Koolstra 1 month ago
> Op 08-03-2026 17:19 CET schreef Greg KH <gregkh@linuxfoundation.org>:
> 
>  
> On Sun, Mar 08, 2026 at 01:39:12PM +0100, Jori Koolstra wrote:
> > diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
> > index 9f093176b8db..34403582c895 100644
> > --- a/arch/powerpc/platforms/powernv/vas-window.c
> > +++ b/arch/powerpc/platforms/powernv/vas-window.c
> > @@ -1459,7 +1459,6 @@ static const struct vas_user_win_ops vops =  {
> >  int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> >  			     const char *name)
> >  {
> > -
> >  	return vas_register_coproc_api(mod, cop_type, name, &vops);
> >  }
> >  EXPORT_SYMBOL_GPL(vas_register_api_powernv);
> > 
> 
> This change wasn't needed here :(
> 
> thanks,
> 
> greg k-h

My bad, I meant to copy this here instead of at the top of me last email:

Now checkpatch complains that:

CHECK: Blank lines aren't necessary after an open brace '{'

So the rule is: don't touch white space unless you absolutely have to?

That is good to know to prevent silly v2's. I know that non-functional
changes are frowned upon; but you also shouldn't sneak in a white space
fixes?

Again, sorry for the silly v2.
Re: [PATCH] powerpc: vas-api: constify dynamic struct class in coproc api register
Posted by Greg KH 1 month ago
On Sun, Mar 08, 2026 at 11:15:40PM +0100, Jori Koolstra wrote:
> 
> > Op 08-03-2026 17:19 CET schreef Greg KH <gregkh@linuxfoundation.org>:
> > 
> >  
> > On Sun, Mar 08, 2026 at 01:39:12PM +0100, Jori Koolstra wrote:
> > > diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
> > > index 9f093176b8db..34403582c895 100644
> > > --- a/arch/powerpc/platforms/powernv/vas-window.c
> > > +++ b/arch/powerpc/platforms/powernv/vas-window.c
> > > @@ -1459,7 +1459,6 @@ static const struct vas_user_win_ops vops =  {
> > >  int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> > >  			     const char *name)
> > >  {
> > > -
> > >  	return vas_register_coproc_api(mod, cop_type, name, &vops);
> > >  }
> > >  EXPORT_SYMBOL_GPL(vas_register_api_powernv);
> > > 
> > 
> > This change wasn't needed here :(
> > 
> > thanks,
> > 
> > greg k-h
> 
> My bad, I meant to copy this here instead of at the top of me last email:
> 
> Now checkpatch complains that:
> 
> CHECK: Blank lines aren't necessary after an open brace '{'

That's true, but don't mix patches together, and usually, for code
outside of drivers/staging/ don't worry about checkpatch issues.

> So the rule is: don't touch white space unless you absolutely have to?
> 
> That is good to know to prevent silly v2's. I know that non-functional
> changes are frowned upon; but you also shouldn't sneak in a white space
> fixes?

Exactly, don't sneak in anything :)

thanks,

greg k-h