All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver-core: only call kfree() if memory was allocated
@ 2013-08-02 21:43 Andreas Platschek
  2013-08-02 22:04 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Platschek @ 2013-08-02 21:43 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Andreas Platschek

There are several cases where we could bail out of show_uevent()
before kzalloc() is even called. In those cases we don't want to
call kfree().

In addition the error handling of kzalloc() is now using the
single point of exit as well.

Signed-off-by: Andreas Platschek <andi.platschek@gmail.com>
---
 drivers/base/core.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8856d74..bf4effb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -372,8 +372,10 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
 			goto out;
 
 	env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
-	if (!env)
-		return -ENOMEM;
+	if (!env) {
+		count = -ENOMEM;
+		goto out;
+	}
 
 	/* let the kset specific function add its keys */
 	retval = kset->uevent_ops->uevent(kset, &dev->kobj, env);
@@ -383,8 +385,9 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
 	/* copy keys to file */
 	for (i = 0; i < env->envp_idx; i++)
 		count += sprintf(&buf[count], "%s\n", env->envp[i]);
-out:
+out_free:
 	kfree(env);
+out:
 	return count;
 }
 
-- 
1.7.10.4


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

* Re: [PATCH] driver-core: only call kfree() if memory was allocated
  2013-08-02 21:43 [PATCH] driver-core: only call kfree() if memory was allocated Andreas Platschek
@ 2013-08-02 22:04 ` Greg KH
  2013-08-03  9:22   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2013-08-02 22:04 UTC (permalink / raw)
  To: Andreas Platschek; +Cc: linux-kernel

On Fri, Aug 02, 2013 at 11:43:50PM +0200, Andreas Platschek wrote:
> There are several cases where we could bail out of show_uevent()
> before kzalloc() is even called. In those cases we don't want to
> call kfree().

Why not?  It's totally safe to do that.

> In addition the error handling of kzalloc() is now using the
> single point of exit as well.

We had the single point of exit to start with, there's no change made
there.

Sorry, but I'm not going to take this patch, it's not needed.

thanks,

greg k-h

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

* Re: [PATCH] driver-core: only call kfree() if memory was allocated
  2013-08-02 22:04 ` Greg KH
@ 2013-08-03  9:22   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2013-08-03  9:22 UTC (permalink / raw)
  To: Andreas Platschek; +Cc: linux-kernel

On Sat, Aug 03, 2013 at 06:04:45AM +0800, Greg KH wrote:
> On Fri, Aug 02, 2013 at 11:43:50PM +0200, Andreas Platschek wrote:
> > There are several cases where we could bail out of show_uevent()
> > before kzalloc() is even called. In those cases we don't want to
> > call kfree().
> 
> Why not?  It's totally safe to do that.
> 
> > In addition the error handling of kzalloc() is now using the
> > single point of exit as well.
> 
> We had the single point of exit to start with, there's no change made
> there.

Oops, no, you are correct about that one, but it's not really a big deal
for such a small function.

greg k-h

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

end of thread, other threads:[~2013-08-03  9:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02 21:43 [PATCH] driver-core: only call kfree() if memory was allocated Andreas Platschek
2013-08-02 22:04 ` Greg KH
2013-08-03  9:22   ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.