From patchwork Thu Sep 19 10:05:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 11152075 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C25414DB for ; Thu, 19 Sep 2019 10:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA3E121924 for ; Thu, 19 Sep 2019 10:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YJ3anWqk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389098AbfISKF6 (ORCPT ); Thu, 19 Sep 2019 06:05:58 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34886 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389018AbfISKF6 (ORCPT ); Thu, 19 Sep 2019 06:05:58 -0400 Received: by mail-wm1-f66.google.com with SMTP id y21so3266267wmi.0 for ; Thu, 19 Sep 2019 03:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0qCMMPkPMs7VBfcvx3JaPL0V56C94XiExPoi5TYfUdo=; b=YJ3anWqkz3yfMdDXZlWvfwd2aRSX1GEWmuiEvzP4HnRI/QUu14biCE0o0kKjREXsCf KuW4986tQaHaCZuqMpurrkj8rK6Txizw1DhqQIJ4AWTDSZ9yeaLNKdWapvPAu+a1e0Wy 0NKhkRAFN1BL+Fro8CrV82lsXppSNdtTsQJBE1IVuxoJfBHtHV0Ve6IKj8vqag92lSBl 6fHu8EODi8AyrZZvYOiJJa6KyqEiyjkvyJH8Hg6zgKhSxat7GGzDkPtc1y9q0pGjD6ZO JZI34ycmL8mzIKssv01a5fULUS5KbRJnJUBPhdgzDG+SPSdDnQJYtuJplCrc7J5SExLd xijQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0qCMMPkPMs7VBfcvx3JaPL0V56C94XiExPoi5TYfUdo=; b=iu/D/W39Ebvn1GdGl8tdznrevszELD+PgsmbDFYUV4DNaZESLy0paLAZ0zFXnXFjFB RfmfNcx7dmBl/1LikRtYrLogMycH0DPOSPlK5/mCvNwc5ZerFuLRHvK4gIFo+E87/PK7 zMeVbfShErA3izYVQgNJqJm382awz1M7ODGKmG+YemqI9iESRh8fNXDVXCRA38UrrTcG 05o/MSCA+VjMdDchIWSaAQsg5eLVQCr39Q1awFLQuaUGGrwQRsLDThsugeg6DVepFAir zdMy2Lh/wAHdXQUrfJoAZvgOt+xKUBLkcWI25WMM+j1PDTTZZ8upjhdBpkAIsDp31dQO Uu2w== X-Gm-Message-State: APjAAAX6+sioEI+ZELhpOVQPdY6RCqOeR50DDn00vbVYlsK1P4QvxmtS 6RyrghekEalNk4wd0Wm4Otr74A== X-Google-Smtp-Source: APXvYqxgniKjpSqUKCq3LuuJ49giEyIk2zZbAqW994p+uQN2HoctohFog3xIGNP6T7hvGty7R9NUXQ== X-Received: by 2002:a7b:c4d6:: with SMTP id g22mr2081077wmk.21.1568887556601; Thu, 19 Sep 2019 03:05:56 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id s10sm8590175wmf.48.2019.09.19.03.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 03:05:56 -0700 (PDT) From: Srinivas Kandagatla To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH] rpmsg: glink: Fix channel memory leak Date: Thu, 19 Sep 2019 11:05:40 +0100 Message-Id: <20190919100540.28159-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org If we stop and start the dsp while channel is open then there is a leak in the driver as the refcount is not accounted for the open. This patch checks if the channel is open while running cleanup code and does an extra kref_put to account for open which would ensure that channel does not leak. Originally detected by kmemleak: backtrace: [] kmemleak_alloc+0x50/0x84 [] kmem_cache_alloc_trace+0xd4/0x178 [] qcom_glink_alloc_channel+0x34/0x148 [] qcom_glink_work+0x3b0/0x664 [] process_one_work+0x160/0x2f8 [] worker_thread+0x1e8/0x2d4 [] kthread+0x128/0x138 [] ret_from_fork+0x10/0x18 [] 0xffffffffffffffff unreferenced object 0xffffffc02cf5ed80 (size 128): Signed-off-by: Srinivas Kandagatla --- drivers/rpmsg/qcom_glink_native.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index dc7d3d098fd3..38a10dcc2029 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1660,8 +1660,13 @@ void qcom_glink_native_remove(struct qcom_glink *glink) spin_lock_irqsave(&glink->idr_lock, flags); /* Release any defunct local channels, waiting for close-ack */ - idr_for_each_entry(&glink->lcids, channel, cid) + idr_for_each_entry(&glink->lcids, channel, cid) { + if (channel->rcid) + kref_put(&channel->refcount, + qcom_glink_channel_release); + kref_put(&channel->refcount, qcom_glink_channel_release); + } /* Release any defunct local channels, waiting for close-req */ idr_for_each_entry(&glink->rcids, channel, cid)