From patchwork Sun Jun 12 14:56:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 9171535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 157AC6044F for ; Sun, 12 Jun 2016 14:56:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A1E724151 for ; Sun, 12 Jun 2016 14:56:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F257327C2D; Sun, 12 Jun 2016 14:56:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B4DF24151 for ; Sun, 12 Jun 2016 14:56:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A5896E031; Sun, 12 Jun 2016 14:56:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4BC196E031; Sun, 12 Jun 2016 14:56:43 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id k184so9197632wme.2; Sun, 12 Jun 2016 07:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4Yu4lDKFosvDOBAHmjysZQiQoiMjUBxOU2tDobKp5HI=; b=TzegYuzjcLkBXFWHPPTqgaVgaAmMYoT8S0FxX5Gc9HyOipqNc67MuTeRjs0h/Dg/Kl xU3Z9AwOA4AehSrc3uea651gOdxK4B2gCNZx6umKpNfsTRmHPNPi9AzsUtanfruICfvC /0eFVKybVopkk8DRKBMbHXr7q9wiu/5i9MXOrv4vrFTwtXRhuItOGfk8DBvWxvTJ22Ot j5YW+StTlx4UbyAhDuSGNbnfXNMuW9HX7C+Up9xLIVL9+h6pqWYcPBglmuSQiOfVqLge RT0RROVNPVs5CCcU9QKxORY3SjiU0D+ukeT0hd0N/gW5m3CPn6J8fs39bvefdKKV6nHS s2GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4Yu4lDKFosvDOBAHmjysZQiQoiMjUBxOU2tDobKp5HI=; b=O5AtBD5hBTYuHgDcb2A9yCcDAD8GWpKetO3eW1JKI1lSm1jWmRI4uDbAmbIe06Jjl2 MW9H5iQaFaIYkc/PotsrMdjJQmWhtPPyn6iQT4G2SyV+ANbtwNVcgHeTeX8Zm+u7eO1v DOQvPL9c3m2zMjcNfN3IyBJdMPvuYuxuzb9ievgtieaNiG5z7a0meOOi503iDalNm4DN fJ8sUGALkJQ38lLuzvuqIS3QhUOFpn3wWYi7+g5rYkCCK34WLX+oYRYd4PFxJE8HqOXE Sre0zhRIPjlUdPGGR5ccbKhtMrLpr4XclPf2V9KI6+w9XKKlyoJSLSjcNo2RgFHPF8Ak TJeQ== X-Gm-Message-State: ALyK8tIg0a8bQBOetWahAqgjGCQHl8qq3N7LLFHVdJJzV8boIbSFPFxD27+W+DZ6Y1DJSg== X-Received: by 10.194.203.37 with SMTP id kn5mr10486506wjc.42.1465743401589; Sun, 12 Jun 2016 07:56:41 -0700 (PDT) Received: from sudip-laptop.lan (234.98.208.46.dyn.plus.net. [46.208.98.234]) by smtp.gmail.com with ESMTPSA id g3sm22644431wjb.47.2016.06.12.07.56.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Jun 2016 07:56:40 -0700 (PDT) From: Sudip Mukherjee To: Ben Skeggs , David Airlie Subject: [PATCH] drm/nouveau/iccsense: fix memory leak Date: Sun, 12 Jun 2016 15:56:34 +0100 Message-Id: <1465743394-6027-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 Cc: nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sudip Mukherjee X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the for loop we are allocating the memory for rail everytime but in some cases we use "continue" and in those cases the memory already allocated for rail is leaked and we again allocate new memory for it. Lets free the memory before continuing with the loop. Signed-off-by: Sudip Mukherjee --- drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c index 323c79a..756ff07 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c @@ -290,21 +290,28 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) switch (sensor->type) { case NVBIOS_EXTDEV_INA209: - if (r->rail != 0) + if (r->rail != 0) { + kfree(rail); continue; + } rail->read = nvkm_iccsense_ina209_read; break; case NVBIOS_EXTDEV_INA219: - if (r->rail != 0) + if (r->rail != 0) { + kfree(rail); continue; + } rail->read = nvkm_iccsense_ina219_read; break; case NVBIOS_EXTDEV_INA3221: - if (r->rail >= 3) + if (r->rail >= 3) { + kfree(rail); continue; + } rail->read = nvkm_iccsense_ina3221_read; break; default: + kfree(rail); continue; }