LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, sensors@stimpy.netroedge.com
Subject: Re: [PATCH] I2C update for 2.6.6
Date: Fri, 14 May 2004 16:29:17 -0700	[thread overview]
Message-ID: <10845773571232@kroah.com> (raw)
In-Reply-To: <10845773573553@kroah.com>

ChangeSet 1.1587.15.10, 2004/05/05 15:34:40-07:00, khali@linux-fr.org

[PATCH] I2C: Fix memory leaks in w83781d and asb100

Quoting myself

> U-ho. I think I've introduced a memory leak with this patch :(
>
> For drivers that handle subclients (asb100 and w83781d on i2c), the
> sublient memory is never released if I read the code correctly. This
> is because we now free the private data on unload, assuming that it
> contains the i2c client data as well. That's true for the main i2c
> client, but not for the subclients (data == NULL so nothing is freed).
>
> Could someone take a look and confirm?

I could test and actually saw memory leaking when cycling the w83781d
driver at a sustained rate (5/s).

> I can see two different fixes:
>
> 1* When freeing the memory, free the data if it's not NULL (main
> client), else free client (subclients). Cleaner (I suppose?).
>
> 2* When creating subclients, do data = &client instead of data = NULL.
> Then freeing will work. Less code, faster. Are there side effects? (I
> don't think so)
>
> My preference would go to 2*.

I ended up implementing 1*. That's cleaner and there's actually almost
no extra code.

Mark, can you confirm that I'm doing the correct thing? I'll do
something similar in our CVS repository (for now, the asb100 and w83781d
drivers had not their memory allocation scheme reworked there).


 drivers/i2c/chips/asb100.c  |    8 +++++++-
 drivers/i2c/chips/w83781d.c |    8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)


diff -Nru a/drivers/i2c/chips/asb100.c b/drivers/i2c/chips/asb100.c
--- a/drivers/i2c/chips/asb100.c	Fri May 14 16:19:58 2004
+++ b/drivers/i2c/chips/asb100.c	Fri May 14 16:19:58 2004
@@ -855,7 +855,13 @@
 		return err;
 	}
 
-	kfree(i2c_get_clientdata(client));
+	if (i2c_get_clientdata(client)==NULL) {
+		/* subclients */
+		kfree(client);
+	} else {
+		/* main client */
+		kfree(i2c_get_clientdata(client));
+	}
 
 	return 0;
 }
diff -Nru a/drivers/i2c/chips/w83781d.c b/drivers/i2c/chips/w83781d.c
--- a/drivers/i2c/chips/w83781d.c	Fri May 14 16:19:58 2004
+++ b/drivers/i2c/chips/w83781d.c	Fri May 14 16:19:58 2004
@@ -1336,7 +1336,13 @@
 		return err;
 	}
 
-	kfree(i2c_get_clientdata(client));
+	if (i2c_get_clientdata(client)==NULL) {
+		/* subclients */
+		kfree(client);
+	} else {
+		/* main client */
+		kfree(i2c_get_clientdata(client));
+	}
 
 	return 0;
 }


  reply	other threads:[~2004-05-14 23:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-14 23:27 [BK PATCH] " Greg KH
2004-05-14 23:29 ` [PATCH] " Greg KH
2004-05-14 23:29   ` Greg KH
2004-05-14 23:29     ` Greg KH
2004-05-14 23:29       ` Greg KH
2004-05-14 23:29         ` Greg KH
2004-05-14 23:29           ` Greg KH
2004-05-14 23:29             ` Greg KH
2004-05-14 23:29               ` Greg KH
2004-05-14 23:29                 ` Greg KH
2004-05-14 23:29                   ` Greg KH [this message]
2004-05-14 23:29                     ` Greg KH
2004-05-14 23:29                       ` Greg KH
2004-05-14 23:29                         ` Greg KH
2004-05-14 23:29                           ` Greg KH
2004-05-14 23:29                             ` Greg KH
2004-05-14 23:29                               ` Greg KH
2004-05-14 23:29                                 ` Greg KH
2004-05-14 23:29                                   ` Greg KH

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=10845773571232@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sensors@stimpy.netroedge.com \
    --subject='Re: [PATCH] I2C update for 2.6.6' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).