lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ae5840f3-7e19-4d60-bd87-567068a3f813@xs4all.nl>
Date: Mon, 8 Apr 2024 11:47:42 +0200
From: Hans Verkuil <hverkuil@...all.nl>
To: "Ricardo B. Marliere" <ricardo@...liere.net>,
 Mauro Carvalho Chehab <mchehab@...nel.org>, Sean Young <sean@...s.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
 linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] media: dvbdev: make dvb_class constant

On 05/03/2024 14:26, Ricardo B. Marliere wrote:
> Since commit 43a7206b0963 ("driver core: class: make class_register() take
> a const *"), the driver core allows for struct class to be in read-only
> memory, so move the dvb_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.
> 
> Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Ricardo B. Marliere <ricardo@...liere.net>
> ---
>  drivers/media/dvb-core/dvbdev.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 733d0bc4b4cc..dcbf68b00240 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -78,7 +78,13 @@ static const u8 minor_type[] = {
>  #define MAX_DVB_MINORS		(DVB_MAX_ADAPTERS * 64)
>  #endif
>  
> -static struct class *dvb_class;
> +static int dvb_uevent(const struct device *dev, struct kobj_uevent_env *env);
> +static char *dvb_devnode(const struct device *dev, umode_t *mode);

Forward references are typically something you want to avoid.

Looking at the code, I think it makes sense to just move those two functions
to just before this dvb_class.

> +static const struct class dvb_class = {
> +	.name = "dvb",
> +	.dev_uevent = dvb_uevent,
> +	.devnode = dvb_devnode,
> +};
>  
>  static struct dvb_device *dvb_minors[MAX_DVB_MINORS];
>  static DECLARE_RWSEM(minor_rwsem);

Also move the dvb_class (+ the two functions) to after this line. I think that's
a more suitable place for this.

> @@ -561,7 +567,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
>  		return ret;
>  	}
>  
> -	clsdev = device_create(dvb_class, adap->device,
> +	clsdev = device_create(&dvb_class, adap->device,
>  			       MKDEV(DVB_MAJOR, minor),
>  			       dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id);
>  	if (IS_ERR(clsdev)) {
> @@ -600,7 +606,7 @@ void dvb_remove_device(struct dvb_device *dvbdev)
>  
>  	dvb_media_device_free(dvbdev);
>  
> -	device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
> +	device_destroy(&dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
>  
>  	list_del(&dvbdev->list_head);
>  }
> @@ -1096,13 +1102,10 @@ static int __init init_dvbdev(void)
>  		goto error;
>  	}
>  
> -	dvb_class = class_create("dvb");
> -	if (IS_ERR(dvb_class)) {
> -		retval = PTR_ERR(dvb_class);
> +	retval = class_register(&dvb_class);
> +	if (retval != 0)

This can just be 'if (retval)'.

>  		goto error;
> -	}
> -	dvb_class->dev_uevent = dvb_uevent;
> -	dvb_class->devnode = dvb_devnode;
> +
>  	return 0;
>  
>  error:
> @@ -1115,7 +1118,7 @@ static void __exit exit_dvbdev(void)
>  {
>  	struct dvbdevfops_node *node, *next;
>  
> -	class_destroy(dvb_class);
> +	class_unregister(&dvb_class);
>  	cdev_del(&dvb_device_cdev);
>  	unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
>  
> 

Regards,

	Hans

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ