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: <ZNWnTxcRtx+tcQqF@yilunxu-OptiPlex-7050>
Date:   Fri, 11 Aug 2023 11:13:19 +0800
From:   Xu Yilun <yilun.xu@...el.com>
To:     Ivan Orlov <ivan.orlov0322@...il.com>
Cc:     mdf@...nel.org, hao.wu@...el.com, trix@...hat.com,
        linux-fpga@...r.kernel.org, linux-kernel@...r.kernel.org,
        gregkh@...uxfoundation.org
Subject: Re: [PATCH 3/3] fpga: region: make fpga_region_class a static const
 structure

On 2023-08-10 at 21:22:10 +0400, Ivan Orlov wrote:
> Now that the driver core allows for struct class to be in read-only
> memory, move the fpga_region_class structure to be declared at build
> time placing it into read-only memory, instead of having to be
> dynamically allocated at boot time.
> 
> Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@...il.com>
> ---
>  drivers/fpga/fpga-region.c | 64 ++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
> index ccf6fdab1360..01cf4c2f83d1 100644
> --- a/drivers/fpga/fpga-region.c
> +++ b/drivers/fpga/fpga-region.c
> @@ -16,21 +16,6 @@
>  #include <linux/spinlock.h>
>  
>  static DEFINE_IDA(fpga_region_ida);
> -static struct class *fpga_region_class;
> -
> -struct fpga_region *
> -fpga_region_class_find(struct device *start, const void *data,
> -		       int (*match)(struct device *, const void *))
> -{
> -	struct device *dev;
> -
> -	dev = class_find_device(fpga_region_class, start, data, match);
> -	if (!dev)
> -		return NULL;
> -
> -	return to_fpga_region(dev);
> -}
> -EXPORT_SYMBOL_GPL(fpga_region_class_find);
>  
>  /**
>   * fpga_region_get - get an exclusive reference to an fpga region
> @@ -179,6 +164,34 @@ static struct attribute *fpga_region_attrs[] = {
>  };
>  ATTRIBUTE_GROUPS(fpga_region);
>  
> +static void fpga_region_dev_release(struct device *dev)
> +{
> +	struct fpga_region *region = to_fpga_region(dev);
> +
> +	ida_free(&fpga_region_ida, region->dev.id);
> +	kfree(region);
> +}
> +
> +static const struct class fpga_region_class = {
> +	.name = "fpga_region",
> +	.dev_groups = fpga_region_groups,
> +	.dev_release = fpga_region_dev_release,
> +};

Same concern as previous patches。

Thanks,
Yilun

> +
> +struct fpga_region *
> +fpga_region_class_find(struct device *start, const void *data,
> +		       int (*match)(struct device *, const void *))
> +{
> +	struct device *dev;
> +
> +	dev = class_find_device(&fpga_region_class, start, data, match);
> +	if (!dev)
> +		return NULL;
> +
> +	return to_fpga_region(dev);
> +}
> +EXPORT_SYMBOL_GPL(fpga_region_class_find);
> +
>  /**
>   * fpga_region_register_full - create and register an FPGA Region device
>   * @parent: device parent
> @@ -216,7 +229,7 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info *
>  	mutex_init(&region->mutex);
>  	INIT_LIST_HEAD(&region->bridge_list);
>  
> -	region->dev.class = fpga_region_class;
> +	region->dev.class = &fpga_region_class;
>  	region->dev.parent = parent;
>  	region->dev.of_node = parent->of_node;
>  	region->dev.id = id;
> @@ -279,33 +292,18 @@ void fpga_region_unregister(struct fpga_region *region)
>  }
>  EXPORT_SYMBOL_GPL(fpga_region_unregister);
>  
> -static void fpga_region_dev_release(struct device *dev)
> -{
> -	struct fpga_region *region = to_fpga_region(dev);
> -
> -	ida_free(&fpga_region_ida, region->dev.id);
> -	kfree(region);
> -}
> -
>  /**
>   * fpga_region_init - init function for fpga_region class
>   * Creates the fpga_region class and registers a reconfig notifier.
>   */
>  static int __init fpga_region_init(void)
>  {
> -	fpga_region_class = class_create("fpga_region");
> -	if (IS_ERR(fpga_region_class))
> -		return PTR_ERR(fpga_region_class);
> -
> -	fpga_region_class->dev_groups = fpga_region_groups;
> -	fpga_region_class->dev_release = fpga_region_dev_release;
> -
> -	return 0;
> +	return class_register(&fpga_region_class);
>  }
>  
>  static void __exit fpga_region_exit(void)
>  {
> -	class_destroy(fpga_region_class);
> +	class_unregister(&fpga_region_class);
>  	ida_destroy(&fpga_region_ida);
>  }
>  
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ