Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH 1/2] staging: axis-fifo: remove unnecessary dev_set_drvdata() calls
@ 2025-08-08 20:48 Ovidiu Panait
  2025-08-08 20:48 ` [PATCH 2/2] staging: axis-fifo: use unique identifiers in device names Ovidiu Panait
  0 siblings, 1 reply; 3+ messages in thread
From: Ovidiu Panait @ 2025-08-08 20:48 UTC (permalink / raw)
  To: gregkh, linux-kernel, linux-staging; +Cc: Ovidiu Panait

Remove unnecessary dev_set_drvdata() calls - driver_data will be set to
NULL in device_unbind_cleanup() at driver exit time.

This allows us to remove the 'err_initial' label, simplifying the probe
function a bit.

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
---
 drivers/staging/axis-fifo/axis-fifo.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 57ed58065eba..06f7cfab4c6a 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -693,10 +693,8 @@ static int axis_fifo_probe(struct platform_device *pdev)
 
 	/* get iospace for the device and request physical memory */
 	fifo->base_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
-	if (IS_ERR(fifo->base_addr)) {
-		rc = PTR_ERR(fifo->base_addr);
-		goto err_initial;
-	}
+	if (IS_ERR(fifo->base_addr))
+		return PTR_ERR(fifo->base_addr);
 
 	dev_dbg(fifo->dt_device, "remapped memory to 0x%p\n", fifo->base_addr);
 
@@ -711,7 +709,7 @@ static int axis_fifo_probe(struct platform_device *pdev)
 
 	rc = axis_fifo_parse_dt(fifo);
 	if (rc)
-		goto err_initial;
+		return rc;
 
 	reset_ip_core(fifo);
 
@@ -723,7 +721,7 @@ static int axis_fifo_probe(struct platform_device *pdev)
 	/* get IRQ resource */
 	rc = platform_get_irq(pdev, 0);
 	if (rc < 0)
-		goto err_initial;
+		return rc;
 
 	/* request IRQ */
 	fifo->irq = rc;
@@ -732,7 +730,7 @@ static int axis_fifo_probe(struct platform_device *pdev)
 	if (rc) {
 		dev_err(fifo->dt_device, "couldn't allocate interrupt %i\n",
 			fifo->irq);
-		goto err_initial;
+		return rc;
 	}
 
 	/* ----------------------------
@@ -747,15 +745,11 @@ static int axis_fifo_probe(struct platform_device *pdev)
 	fifo->miscdev.parent = dev;
 	rc = misc_register(&fifo->miscdev);
 	if (rc < 0)
-		goto err_initial;
+		return rc;
 
 	axis_fifo_debugfs_init(fifo);
 
 	return 0;
-
-err_initial:
-	dev_set_drvdata(dev, NULL);
-	return rc;
 }
 
 static void axis_fifo_remove(struct platform_device *pdev)
@@ -765,7 +759,6 @@ static void axis_fifo_remove(struct platform_device *pdev)
 
 	debugfs_remove(fifo->debugfs_dir);
 	misc_deregister(&fifo->miscdev);
-	dev_set_drvdata(dev, NULL);
 }
 
 static const struct of_device_id axis_fifo_of_match[] = {
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] staging: axis-fifo: use unique identifiers in device names
  2025-08-08 20:48 [PATCH 1/2] staging: axis-fifo: remove unnecessary dev_set_drvdata() calls Ovidiu Panait
@ 2025-08-08 20:48 ` Ovidiu Panait
  2025-08-10 14:41   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Ovidiu Panait @ 2025-08-08 20:48 UTC (permalink / raw)
  To: gregkh, linux-kernel, linux-staging; +Cc: Ovidiu Panait

Axis-fifo devices use physical addresses in their name, for example
'axis_fifo_0x43c00000'. This is generally frowned upon and it does not
follow the usual naming scheme that uses unique identifiers.

Therefore, use ida_alloc()/ida_free() to implement unique identifiers
for axis-fifo device names (i.e. axis-fifo0, axis-fifo1, etc.).

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
---
 drivers/staging/axis-fifo/axis-fifo.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 06f7cfab4c6a..27e12af25bc7 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -107,6 +107,8 @@
 static long read_timeout = 1000; /* ms to wait before read() times out */
 static long write_timeout = 1000; /* ms to wait before write() times out */
 
+static DEFINE_IDA(axis_fifo_ida);
+
 /* ----------------------------
  * module command-line arguments
  * ----------------------------
@@ -123,6 +125,7 @@ MODULE_PARM_DESC(write_timeout, "ms to wait before blocking write() timing out;
  */
 
 struct axis_fifo {
+	int id;
 	int irq; /* interrupt */
 	void __iomem *base_addr; /* kernel space memory */
 
@@ -698,10 +701,6 @@ static int axis_fifo_probe(struct platform_device *pdev)
 
 	dev_dbg(fifo->dt_device, "remapped memory to 0x%p\n", fifo->base_addr);
 
-	/* create unique device name */
-	snprintf(device_name, 32, "%s_%pa", DRIVER_NAME, &r_mem->start);
-	dev_dbg(fifo->dt_device, "device name [%s]\n", device_name);
-
 	/* ----------------------------
 	 *          init IP
 	 * ----------------------------
@@ -737,6 +736,11 @@ static int axis_fifo_probe(struct platform_device *pdev)
 	 *      init char device
 	 * ----------------------------
 	 */
+	fifo->id = ida_alloc(&axis_fifo_ida, GFP_KERNEL);
+	if (fifo->id < 0)
+		return fifo->id;
+
+	snprintf(device_name, 32, "%s%d", DRIVER_NAME, fifo->id);
 
 	/* create character device */
 	fifo->miscdev.fops = &fops;
@@ -744,8 +748,10 @@ static int axis_fifo_probe(struct platform_device *pdev)
 	fifo->miscdev.name = device_name;
 	fifo->miscdev.parent = dev;
 	rc = misc_register(&fifo->miscdev);
-	if (rc < 0)
+	if (rc < 0) {
+		ida_free(&axis_fifo_ida, fifo->id);
 		return rc;
+	}
 
 	axis_fifo_debugfs_init(fifo);
 
@@ -759,6 +765,7 @@ static void axis_fifo_remove(struct platform_device *pdev)
 
 	debugfs_remove(fifo->debugfs_dir);
 	misc_deregister(&fifo->miscdev);
+	ida_free(&axis_fifo_ida, fifo->id);
 }
 
 static const struct of_device_id axis_fifo_of_match[] = {
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] staging: axis-fifo: use unique identifiers in device names
  2025-08-08 20:48 ` [PATCH 2/2] staging: axis-fifo: use unique identifiers in device names Ovidiu Panait
@ 2025-08-10 14:41   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-08-10 14:41 UTC (permalink / raw)
  To: Ovidiu Panait; +Cc: linux-kernel, linux-staging

On Fri, Aug 08, 2025 at 11:48:31PM +0300, Ovidiu Panait wrote:
> Axis-fifo devices use physical addresses in their name, for example
> 'axis_fifo_0x43c00000'. This is generally frowned upon and it does not
> follow the usual naming scheme that uses unique identifiers.
> 
> Therefore, use ida_alloc()/ida_free() to implement unique identifiers
> for axis-fifo device names (i.e. axis-fifo0, axis-fifo1, etc.).
> 
> Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
> ---
>  drivers/staging/axis-fifo/axis-fifo.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
> index 06f7cfab4c6a..27e12af25bc7 100644
> --- a/drivers/staging/axis-fifo/axis-fifo.c
> +++ b/drivers/staging/axis-fifo/axis-fifo.c
> @@ -107,6 +107,8 @@
>  static long read_timeout = 1000; /* ms to wait before read() times out */
>  static long write_timeout = 1000; /* ms to wait before write() times out */
>  
> +static DEFINE_IDA(axis_fifo_ida);
> +
>  /* ----------------------------
>   * module command-line arguments
>   * ----------------------------
> @@ -123,6 +125,7 @@ MODULE_PARM_DESC(write_timeout, "ms to wait before blocking write() timing out;
>   */
>  
>  struct axis_fifo {
> +	int id;
>  	int irq; /* interrupt */
>  	void __iomem *base_addr; /* kernel space memory */
>  
> @@ -698,10 +701,6 @@ static int axis_fifo_probe(struct platform_device *pdev)
>  
>  	dev_dbg(fifo->dt_device, "remapped memory to 0x%p\n", fifo->base_addr);
>  
> -	/* create unique device name */
> -	snprintf(device_name, 32, "%s_%pa", DRIVER_NAME, &r_mem->start);
> -	dev_dbg(fifo->dt_device, "device name [%s]\n", device_name);
> -
>  	/* ----------------------------
>  	 *          init IP
>  	 * ----------------------------
> @@ -737,6 +736,11 @@ static int axis_fifo_probe(struct platform_device *pdev)
>  	 *      init char device
>  	 * ----------------------------
>  	 */
> +	fifo->id = ida_alloc(&axis_fifo_ida, GFP_KERNEL);
> +	if (fifo->id < 0)
> +		return fifo->id;
> +
> +	snprintf(device_name, 32, "%s%d", DRIVER_NAME, fifo->id);
>  
>  	/* create character device */
>  	fifo->miscdev.fops = &fops;
> @@ -744,8 +748,10 @@ static int axis_fifo_probe(struct platform_device *pdev)
>  	fifo->miscdev.name = device_name;
>  	fifo->miscdev.parent = dev;
>  	rc = misc_register(&fifo->miscdev);
> -	if (rc < 0)
> +	if (rc < 0) {
> +		ida_free(&axis_fifo_ida, fifo->id);
>  		return rc;
> +	}
>  
>  	axis_fifo_debugfs_init(fifo);
>  
> @@ -759,6 +765,7 @@ static void axis_fifo_remove(struct platform_device *pdev)
>  
>  	debugfs_remove(fifo->debugfs_dir);
>  	misc_deregister(&fifo->miscdev);
> +	ida_free(&axis_fifo_ida, fifo->id);

Did you forget to call ida_destroy() when the module is unloaded?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-10 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-08 20:48 [PATCH 1/2] staging: axis-fifo: remove unnecessary dev_set_drvdata() calls Ovidiu Panait
2025-08-08 20:48 ` [PATCH 2/2] staging: axis-fifo: use unique identifiers in device names Ovidiu Panait
2025-08-10 14:41   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox