public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kernel test robot <lkp@intel.com>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: [resend, PATCH v1 1/2] parport: Clean up resources correctly when parport_register_port() fails
Date: Wed, 18 Oct 2023 17:59:47 +0300	[thread overview]
Message-ID: <20231018145948.1367648-1-andriy.shevchenko@linux.intel.com> (raw)

The smatch warns about uncleaned resources in case the
parport_register_port() fails:

  parport_register_port() warn: '&tmp->full_list' not removed from list

This is indeed an issue introduced when converting code to use
kasprintf(). However, the whole kasprintf() dance in this case
is not needed as dev_set_name() can handle the formatted input
and produces the same result. So, the solution is to delegate
name forming to the dev_set_name() and make device_register()
error path to deal with error handling (via put_device() call).

Fixes: 8d8ae17eb0de ("parport: Use kasprintf() instead of fixed buffer formatting")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202310180809.hepZB9k6-lkp@intel.com/
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/parport/share.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index a9a9cb0477ea..048a459ce4b0 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -361,7 +361,6 @@ static void free_port(struct device *dev)
 		kfree(port->probe_info[d].description);
 	}
 
-	kfree(port->name);
 	kfree(port);
 }
 
@@ -479,16 +478,13 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
 	/*
 	 * Now that the portnum is known finish doing the Init.
 	 */
-	tmp->name = kasprintf(GFP_KERNEL, "parport%d", tmp->portnum);
-	if (!tmp->name) {
-		kfree(tmp);
-		return NULL;
-	}
-	dev_set_name(&tmp->bus_dev, tmp->name);
+	dev_set_name(&tmp->bus_dev, "parport%d", tmp->portnum);
 	tmp->bus_dev.bus = &parport_bus_type;
 	tmp->bus_dev.release = free_port;
 	tmp->bus_dev.type = &parport_device_type;
 
+	tmp->name = dev_name(&tmp->bus_dev);
+
 	for (device = 0; device < 5; device++)
 		/* assume the worst */
 		tmp->probe_info[device].class = PARPORT_CLASS_LEGACY;
-- 
2.40.0.1.gaa8946217a0b


             reply	other threads:[~2023-10-18 15:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 14:59 Andy Shevchenko [this message]
2023-10-18 14:59 ` [resend, PATCH v1 2/2] parport: Drop even more unneeded NULL or 0 assignments Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231018145948.1367648-1-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=sudipm.mukherjee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox