[PATCH] pcmcia/parport_cs: Refactor probe function and improve error logging

Biancaa Ramesh posted 1 patch 11 hours ago
drivers/parport/parport_cs.c | 38 +++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
[PATCH] pcmcia/parport_cs: Refactor probe function and improve error logging
Posted by Biancaa Ramesh 11 hours ago
- Replaced pr_notice with dev_err for proper kernel error logging.
- Added explicit cleanup of link->priv on failure in probe and config.
- Improved comments and readability in parport_probe() and parport_config().
- Ensured allocation checks are consistent (kzalloc returns checked).
- Minor refactoring for clarity and maintainability.

Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
---
 drivers/parport/parport_cs.c | 38 +++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 8e7e3ac4bb87..c6d3f2ee03f7 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -83,19 +83,35 @@ static void parport_cs_release(struct pcmcia_device *);
 static int parport_probe(struct pcmcia_device *link)
 {
     parport_info_t *info;
+    int ret;
 
-    dev_dbg(&link->dev, "parport_attach()\n");
+    dev_dbg(&link->dev, "parport_probe()\n");
 
-    /* Create new parport device */
+    /* Allocate private driver info */
     info = kzalloc(sizeof(*info), GFP_KERNEL);
-    if (!info) return -ENOMEM;
+    if (!info) {
+        dev_err(&link->dev, "failed to allocate parport_info\n");
+        return -ENOMEM;
+    }
+
     link->priv = info;
     info->p_dev = link;
 
+    /* Enable IRQ and auto IO for configuration */
     link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
 
-    return parport_config(link);
-} /* parport_attach */
+    /* Delegate actual configuration to parport_config() */
+    ret = parport_config(link);
+    if (ret) {
+        dev_err(&link->dev, "parport configuration failed\n");
+        kfree(info);
+        link->priv = NULL;
+        return ret;
+    }
+
+    return 0;
+}
+
 
 static void parport_detach(struct pcmcia_device *link)
 {
@@ -141,10 +157,13 @@ static int parport_config(struct pcmcia_device *link)
 			      link->resource[1]->start,
 			      link->irq, PARPORT_DMA_NONE,
 			      &link->dev, IRQF_SHARED);
-    if (p == NULL) {
-	    pr_notice("parport_cs: parport_pc_probe_port() at 0x%3x, irq %u failed\n",
-		      (unsigned int)link->resource[0]->start, link->irq);
-	goto failed;
+    if (!p) {
+        dev_err(&link->dev,
+            "parport_pc_probe_port() failed at 0x%03x, irq %u\n",
+            (unsigned int)link->resource[0]->start, link->irq);
+        goto failed;
+    }   
+
     }
 
     p->modes |= PARPORT_MODE_PCSPP;
@@ -158,6 +177,7 @@ static int parport_config(struct pcmcia_device *link)
 failed:
 	parport_cs_release(link);
 	kfree(link->priv);
+    link->priv = NULL;
 	return -ENODEV;
 } /* parport_config */
 
-- 
2.43.0


-- 
::DISCLAIMER::

---------------------------------------------------------------------
The 
contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only. Views or opinions, if any,
presented in 
this email are solely those of the author and may not
necessarily reflect 
the views or opinions of SSN Institutions (SSN) or its
affiliates. Any form 
of reproduction, dissemination, copying, disclosure,
modification, 
distribution and / or publication of this message without the
prior written 
consent of authorized representative of SSN is strictly
prohibited. If you 
have received this email in error please delete it and
notify the sender 
immediately.
---------------------------------------------------------------------
Header of this mail should have a valid DKIM signature for the domain 
ssn.edu.in <http://www.ssn.edu.in/>