Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1589428imu; Tue, 6 Nov 2018 00:46:54 -0800 (PST) X-Google-Smtp-Source: AJdET5d1jd0q/5CHYcr8g7OtMAnAz6MDkUApEpcq+Jb8rm36EIUT/LYS3wrAH4BOoBMdhubvhJm8 X-Received: by 2002:a62:178c:: with SMTP id 134-v6mr25849377pfx.29.1541494014562; Tue, 06 Nov 2018 00:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541494014; cv=none; d=google.com; s=arc-20160816; b=XmDCYbqSzDBnrgsmvIyoSbJsA8Gt1h8b6OBxH6Yyl1AeDlTS7YStWQzvMD8BYDhy/D fq0BqzLarhO/cespx86Izpe898keyzLmCS5hJ5n69qtS4LgXKNAaIz4IH1So38UjQjr7 zKLR0l/cU1YcUhsiDB24gr0BkhfInJ+NkLH5OMVJSq0bZ4ggQEcCzyB8fU+nIfK8HLDf Jpr6gMkpicQX9UUGUdAp068tp1jBQr3cRcqKzPEasyliCrb/AkQMOwqmhP2UmErOJQFU Iqi+qxG+4gyGWNhpBbbHLPk8jwUr+7BZp34ceDxR9yjMdm6DfMve4N28Vvs/JQxiSq71 jsgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=k8FmS3CIaGNVpZfWOhih1e93J61tsSGysj3YnWo6DBE=; b=PC9UR/gWApwYjN20ihqUlXP1bWxbNl8zCrTH5M459VBiVEqK7JS9NTsH54bbiLS84c t3lkhcXqC+anT5CvNmBACFyUtOTdTM+6nF7U3ETJGxdEesnHnH3e3INGdVhvMdDrcWeF K4DCrS13LqIjT5wuKdXu8ny7MPl8XU0/jdurXgDaGFB6loafKZkWcW5b+ZHNSL5tjHa3 Bul0o8Gj2uR319xegvxc2aYTQ6nDJkOjy+gLTU1mMqLbU1fCeXgU1cK0KF4met9tg2zb bMidH2153hKCV6qItmlg/y4wJXT/MvDWAVXMnRXl0LmoMALkd/52O4SLuR7LDgiWN73w UOmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si16148272pgr.345.2018.11.06.00.46.39; Tue, 06 Nov 2018 00:46:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730140AbeKFSK1 (ORCPT + 99 others); Tue, 6 Nov 2018 13:10:27 -0500 Received: from mail5.windriver.com ([192.103.53.11]:58982 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729241AbeKFSK0 (ORCPT ); Tue, 6 Nov 2018 13:10:26 -0500 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id wA68i3kv019618 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 6 Nov 2018 00:44:19 -0800 Received: from pek-lpggp4.wrs.com (128.224.153.77) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.3.408.0; Tue, 6 Nov 2018 00:43:59 -0800 From: Xulin Sun To: , CC: , , Subject: [PATCH] rtc: pcf2127: fix a kmemleak caused in pcf2127_i2c_gather_write Date: Tue, 6 Nov 2018 16:42:19 +0800 Message-ID: <1541493739-85733-1-git-send-email-xulin.sun@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pcf2127_i2c_gather_write() allocates memory as local variable for i2c_master_send(), after finishing the master transfer, the allocated memory should be freed. The kmemleak is reported: unreferenced object 0xffff80231e7dba80 (size 64): comm "hwclock", pid 27762, jiffies 4296880075 (age 356.944s) hex dump (first 32 bytes): 03 00 12 03 19 02 11 13 00 80 98 18 00 00 ff ff ................ 00 50 00 00 00 00 00 00 02 00 00 00 00 00 00 00 .P.............. backtrace: [] create_object+0xf8/0x278 [] kmemleak_alloc+0x74/0xa0 [] __kmalloc+0x1ac/0x348 [] pcf2127_i2c_gather_write+0x54/0xf8 [] _regmap_raw_write+0x464/0x850 [] regmap_bulk_write+0x1a4/0x348 [] pcf2127_rtc_set_time+0xac/0xe8 [] rtc_set_time+0x80/0x138 [] rtc_dev_ioctl+0x398/0x610 [] do_vfs_ioctl+0xb0/0x848 [] SyS_ioctl+0x8c/0xa8 [] el0_svc_naked+0x34/0x38 [] 0xffffffffffffffff Signed-off-by: Xulin Sun --- drivers/rtc/rtc-pcf2127.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index e83be18..598e56e 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -248,6 +248,9 @@ static int pcf2127_i2c_gather_write(void *context, memcpy(buf + 1, val, val_size); ret = i2c_master_send(client, buf, val_size + 1); + + kfree(buf); + if (ret != val_size + 1) return ret < 0 ? ret : -EIO; -- 2.7.4