Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4709785ybl; Tue, 4 Feb 2020 00:20:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyiR5RmPOzUhdnGL8Nd4Ea35dI//eSULgzK+pLV9Pu6mP98w2/PrSBFEtaj8emPcdN/i/oV X-Received: by 2002:a05:6830:310c:: with SMTP id b12mr10688058ots.162.1580804440723; Tue, 04 Feb 2020 00:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580804440; cv=none; d=google.com; s=arc-20160816; b=tL13tZQBabLUE9hwrKeWiqQFR7rBRwycKoknaYiDyWiQxcinblVr9kFC24sMaTDI9K 6n4Iyzn28216BmO2ragJoh0KrWPAEMRukFIIQDNdoAG7ntfVK+pxU2lM+gLcac/fu87L nRe1nWs8LIBJ5sJLhhoHQlso0e5T/cztajQt88G9u3+/iMC/ULM1KUsXFqHphB0741+k VU/Zlcg6dQ/RF0cgFTx/QZI5aeXxHkg3RKCVZth6R+lVOMfE331tTATutit2CF9n2rq1 Te627HWXWqWQC73zoLvde6helY3RmdwsyVd5AJtj/ydDUjqKG9MwLznzXQklRZl9H7sX FSkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=e7VapZs7ToFtGQHirc2gqfuZaDOEBKykkyxeoFQPPr0=; b=CiWN3PC10Cg6YnWorEy071oUP9tLX1EhwzDxaWZBViS1/sdk1AEOCNTmSpQArzaPOi Gu99VjyrIZd1kOCMD4TlG0UbdkC2lg9zKypwRv3UH+3zAxw32G/v8taiH04SbdnY/lYM s9SUGdElDRRFx5Ump17koJvGM4ZAW2EHHa0wV5lh6mEZK78aWgYuYqr9DJEwwFkiqbVZ NgAckBNjEm+llYH9uHgHWxkEcRMN5qrBxX7ZxjWeGI9J5BpUU7QHXNk5G1sDDIexaPwF xCWUIwbdF6DMd1qIyE/8DujGYFyv2qdjw/whtAQ2J60+rx5bt3Mu2duS0PY5/TJA81yF GdEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qDFRSO55; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si10698985oic.126.2020.02.04.00.20.28; Tue, 04 Feb 2020 00:20:40 -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; dkim=pass header.i=@linaro.org header.s=google header.b=qDFRSO55; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbgBDIT1 (ORCPT + 99 others); Tue, 4 Feb 2020 03:19:27 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:32914 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbgBDIT1 (ORCPT ); Tue, 4 Feb 2020 03:19:27 -0500 Received: by mail-pj1-f66.google.com with SMTP id m7so708305pjs.0 for ; Tue, 04 Feb 2020 00:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=e7VapZs7ToFtGQHirc2gqfuZaDOEBKykkyxeoFQPPr0=; b=qDFRSO55Rv/R04oSblvygRyyFRoB6x6wb+su1cgyo/BppoM0+ZDgs8RozwgkK78Sci ghPLeZFFf9kILD6GN0VLX2rpGOVtNip/n8BJEM708QGzL5965uow7Dp+dAorskXuSKkd kcn9QHnmSeaZkVwiPSATgkTv8F9ZlkKyJQbYDy3F5BJFrbb4zlsvmlOaGPXaJgwfqoS4 m7OCdxGsCX/2yHJF65AXCxiler2uuqrKAaz6asOH0fvHc1zwYKC7ltO/LKQkLyK6f5hc qu8bXKEK7Qek05xniIc0pewDBxQqbEGS/GplfUOEldjkJJTPWVKvHHvAbehYWChMP6MW WtYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=e7VapZs7ToFtGQHirc2gqfuZaDOEBKykkyxeoFQPPr0=; b=cLbkqDKOg4o5UVCdelb9enVMMMIE7+Iq51UtdnlQCylMGl5UErFIixlm5PzgqOt2MF 97qEyd+ohMb5jm64+tGt61MRO4JyGdtrq6aB9PaBoMmdsHux7VmxGY69fSUS3zfV8OIk CfiNmDZXBMuHISkIbCA1rHSOssRyk6w91j6be5G+qoeAk0X5TM7OKbwCHwT8ZtUe5p2K eSp6Av02HiqzKUJ7fJiEaFfA/cgcDpx+D5sMbPR2foN+WGZF3H6n8k4uaofxPyC4qdpx 0cgTn56KkUBOm0164rBWW5BGnjXyMD4gSTVqlvf1OJusP3yU0uKfXNl9ZwNYbeewN0Vl PcQg== X-Gm-Message-State: APjAAAUko025rcNJzMud7wq3xMCoXXK++upJdDvTfI6egIAdLz/26Fws T/oGk2YfhBd5UjF3N9qydkls X-Received: by 2002:a17:902:b909:: with SMTP id bf9mr27151608plb.96.1580804366289; Tue, 04 Feb 2020 00:19:26 -0800 (PST) Received: from Mani-XPS-13-9360 ([2409:4072:184:5239:5cf8:8075:e072:4b02]) by smtp.gmail.com with ESMTPSA id z29sm22684879pgc.21.2020.02.04.00.19.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Feb 2020 00:19:25 -0800 (PST) Date: Tue, 4 Feb 2020 13:49:16 +0530 From: Manivannan Sadhasivam To: Jakub Kicinski Cc: gregkh@linuxfoundation.org, arnd@arndb.de, smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , netdev@vger.kernel.org Subject: Re: [PATCH v2 14/16] net: qrtr: Add MHI transport layer Message-ID: <20200204081914.GB7452@Mani-XPS-13-9360> References: <20200131135009.31477-1-manivannan.sadhasivam@linaro.org> <20200131135009.31477-15-manivannan.sadhasivam@linaro.org> <20200203101225.43bd27bc@cakuba.hsd1.ca.comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200203101225.43bd27bc@cakuba.hsd1.ca.comcast.net> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jakub, On Mon, Feb 03, 2020 at 10:12:25AM -0800, Jakub Kicinski wrote: > On Fri, 31 Jan 2020 19:20:07 +0530, Manivannan Sadhasivam wrote: > > +/* From QRTR to MHI */ > > +static void qcom_mhi_qrtr_ul_callback(struct mhi_device *mhi_dev, > > + struct mhi_result *mhi_res) > > +{ > > + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev); > > + struct qrtr_mhi_pkt *pkt; > > + unsigned long flags; > > + > > + spin_lock_irqsave(&qdev->ul_lock, flags); > > + pkt = list_first_entry(&qdev->ul_pkts, struct qrtr_mhi_pkt, node); > > + list_del(&pkt->node); > > + complete_all(&pkt->done); > > + > > + kref_put(&pkt->refcount, qrtr_mhi_pkt_release); > > Which kref_get() does this pair with? > > Looks like qcom_mhi_qrtr_send() will release a reference after > completion, too. > Yikes, there is some issue here... Acutally the issue is not in what you referred above but the overall kref handling itself. Please see below. kref_put() should be present in qcom_mhi_qrtr_ul_callback() as it will decrement the refcount which got incremented in qcom_mhi_qrtr_send(). It should be noted that kref_init() will fix the refcount to 1 and kref_get() will increment to 2. So for properly releasing the refcount to 0, we need to call kref_put() twice. So if all goes well, the refcount will get decremented twice in qcom_mhi_qrtr_ul_callback() as well as in qcom_mhi_qrtr_send() and we are good. But, if the transfer has failed ie., when qcom_mhi_qrtr_ul_callback() doesn't get called, then we are leaking the refcount. I need to rework the kref handling code in next iteration. Thanks for triggering this! Regards, Mani > > + spin_unlock_irqrestore(&qdev->ul_lock, flags); > > +}