drm/sysfs: fix up memory leak problem
authoralgea.cao <algea.cao@rock-chips.com>
Tue, 11 Apr 2017 07:36:50 +0000 (15:36 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Wed, 12 Apr 2017 02:08:03 +0000 (10:08 +0800)
Change-Id: I2b4617412b0d5b2897c3cce2ef612a11a9762ba2
Signed-off-by: algea.cao <algea.cao@rock-chips.com>
drivers/gpu/drm/drm_sysfs.c

index ea5aebf023199633778703cda968a4aafaf653eb..3567aaf89995146643174305da4ba77f0c775d53 100644 (file)
@@ -271,11 +271,11 @@ static int drm_get_audio_format(struct edid *edid,
                               char *audioformat, int len)
 {
        int i, size = 0, num = 0;
-       struct cea_sad *sads;
+       struct cea_sad *sads = NULL;
 
        memset(audioformat, 0, len);
        num = drm_edid_to_sad(edid, &sads);
-       if (!num)
+       if (num <= 0)
                return 0;
 
        for (i = 0; i < num; i++) {
@@ -288,6 +288,8 @@ static int drm_get_audio_format(struct edid *edid,
                audioformat[size] = ',';
                audioformat += (size + 1);
        }
+       kfree(sads);
+
        return num;
 }