From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C91EC433F5 for ; Wed, 22 Sep 2021 22:56:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 082E26124E for ; Wed, 22 Sep 2021 22:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238473AbhIVW5y (ORCPT ); Wed, 22 Sep 2021 18:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238293AbhIVW5q (ORCPT ); Wed, 22 Sep 2021 18:57:46 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A19BFC061574 for ; Wed, 22 Sep 2021 15:56:15 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id x124so6881546oix.9 for ; Wed, 22 Sep 2021 15:56:15 -0700 (PDT) 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; bh=j10MBxPavp973rCVehH8eqME/mHuJFVsbejVLw/uZ1o=; b=t3kCB8UqeEJ4R+OdQOJ2Kr82tyKJq0INAPORTdfSBZtDHOS57/KclJOA4xtMKp/y4Z xE4Ao5hmvtJn4eFw9Ac9fCCwprBzAp4zscrJTdykS9cOgmtWhhXbcjKpVnzz4bQ4sorT rtMDzAta0kERkn4qiWcD/6b+8ZdPdWJ4GREkYney9GBK1295oKaDPfTEQ0ggW2Pd2Z4t 8AFGrHPQPaXrTok+yCLfTrYFq3zPW7pFt+gdU+dxn/t33+uODJ46qkswuS+tdFswJrbA 2VULRvJnmY1X3fAunvK2oQrZeBCmbNxJ9i3yLTqh5kEHOJ2LKSWMKxZb5GM3cumFC/ps aYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=j10MBxPavp973rCVehH8eqME/mHuJFVsbejVLw/uZ1o=; b=0mupTWi1hukwpXrVQrApviCH135gbHjGyQHQQK7kYPYoNzkqBf1y/5YgDOXUjHmvjt VF4sD84MYEl2954y6UjdPnMfq2rXgbP0NEiMKgKZ59tcBUG+rn70Ut+AzfUBFYJSVE4h iI6SZszOHsNVpw2NbURVhWI3r9PWtklByGKMrwa5oekHaZ/GuDDOQ6MpoGQjwIyT8fC6 X3yGg2f1iVUu/pG0lLoCpxKpfZ9TuJc6WWQ0RS/cQkdDc5QnQozcTve15Wuvb9kOEXwE WVSm7c2r8hDWX/XSkgr3U9yo3eCEu+lJLbYV6qyAWKsm5ubVBqqX6o8oiaukwQ6wSUMj 4ZnA== X-Gm-Message-State: AOAM530aT7IEhmzJFGTz52cpB11ZbkBX7XvKaxbd6v6IbeLGQu/7PP5W vkaSESPe4jAbpxQ5TowSI3UOnA== X-Google-Smtp-Source: ABdhPJzS3MdJAcPJHwP0ndkMvcbYOvHU9lPuESCiVcd1npUM+NI7qRNbu5hJzqcwFivorcTk+2yCMQ== X-Received: by 2002:aca:b909:: with SMTP id j9mr9984871oif.1.1632351374903; Wed, 22 Sep 2021 15:56:14 -0700 (PDT) Received: from ripper (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id y11sm877508oof.32.2021.09.22.15.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 15:56:14 -0700 (PDT) Date: Wed, 22 Sep 2021 15:56:55 -0700 From: Bjorn Andersson To: Vladimir Zapolskiy Cc: Andy Gross , Kishon Vijay Abraham I , Vinod Koul , Vivek Gautam , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org Subject: Re: [PATCH] phy: qcom-qusb2: Fix a memory leak on probe Message-ID: References: <20210922221613.2115038-1-vladimir.zapolskiy@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210922221613.2115038-1-vladimir.zapolskiy@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Wed 22 Sep 15:16 PDT 2021, Vladimir Zapolskiy wrote: > On success nvmem_cell_read() returns a pointer to a dynamically allocated > buffer, and therefore it shall be freed after usage. > > The issue is reported by kmemleak: > > # cat /sys/kernel/debug/kmemleak > unreferenced object 0xffff3b3803e4b280 (size 128): > comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [<000000007739afdc>] __kmalloc+0x27c/0x41c > [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0 > [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc > [<00000000fc81fcfa>] phy_init+0x70/0x110 > [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234 > [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990 > [<000000001965faf9>] dwc3_probe+0x4f4/0x730 > [<000000002f7617ca>] platform_probe+0x74/0xf0 > [<00000000a2576cac>] really_probe+0xc4/0x470 > [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190 > [<00000000130db71f>] driver_probe_device+0x48/0x110 > [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140 > [<00000000e5812ff7>] bus_for_each_drv+0x84/0xe0 > [<00000000f4bac574>] __device_attach+0xe4/0x1c0 > [<00000000d3beb631>] device_initial_probe+0x20/0x30 > [<000000008019b9db>] bus_probe_device+0xa4/0xb0 > > Fixes: 0b56e9a7e835 ("phy: Group vendor specific phy drivers") > Signed-off-by: Vladimir Zapolskiy > --- > drivers/phy/qualcomm/phy-qcom-qusb2.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c > index 3c1d3b71c825..061665ba8ef7 100644 > --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c > +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c > @@ -589,6 +589,8 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy) > qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2], > val[0] << HSTX_TRIM_SHIFT, > HSTX_TRIM_MASK); > + > + kfree(val); Nice catch, here's my: Reviewed-by: Bjorn Andersson That said, do you think we could replace the nvmem_cell_read() with a call to nvmem_cell_read_u8() to avoid the need to clean it up instead? Regards, Bjorn > } > > static int qusb2_phy_set_mode(struct phy *phy, > -- > 2.33.0 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93019C433EF for ; Wed, 22 Sep 2021 22:56:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A33D60F4C for ; Wed, 22 Sep 2021 22:56:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5A33D60F4C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aQV4yMq3VdXwF3XFAal8prU3fXQBAbQH3NG2pP8zML0=; b=F6PWWsWEZKdzfC qN77mrASR3rV7JA5BO1zW27TE/GKolIR/u11gJ/2xoIqS7gsw+/2QUe6hH4b8RXqt51bXUICPieNN GqJQuQw5u5xIzWuQDs6LBWUNqnisEasT6ON54ohg2vIObis+uKGT2z926F7eS8rnxTnu0NeBjdmnI R0/yVcVSzJCsUwnUcoH0ut+Bfmydxw6PnXzM+zlZujDmpnxc/bb2bZNVZO0AqdtbUpa5k8LjzFMCp PX4BaDDY9C0+fQZfU21b9omlCpLJ2gluBablnXIDlMfS+ra7GTsjvkWBZtMyBNZdDG36p6PonDLR8 +TQVYHqStRThJ5bL1uqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTBA3-009swW-T8; Wed, 22 Sep 2021 22:56:19 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTBA0-009swD-G1 for linux-phy@lists.infradead.org; Wed, 22 Sep 2021 22:56:18 +0000 Received: by mail-oi1-x22f.google.com with SMTP id w206so6942771oiw.4 for ; Wed, 22 Sep 2021 15:56:15 -0700 (PDT) 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; bh=j10MBxPavp973rCVehH8eqME/mHuJFVsbejVLw/uZ1o=; b=t3kCB8UqeEJ4R+OdQOJ2Kr82tyKJq0INAPORTdfSBZtDHOS57/KclJOA4xtMKp/y4Z xE4Ao5hmvtJn4eFw9Ac9fCCwprBzAp4zscrJTdykS9cOgmtWhhXbcjKpVnzz4bQ4sorT rtMDzAta0kERkn4qiWcD/6b+8ZdPdWJ4GREkYney9GBK1295oKaDPfTEQ0ggW2Pd2Z4t 8AFGrHPQPaXrTok+yCLfTrYFq3zPW7pFt+gdU+dxn/t33+uODJ46qkswuS+tdFswJrbA 2VULRvJnmY1X3fAunvK2oQrZeBCmbNxJ9i3yLTqh5kEHOJ2LKSWMKxZb5GM3cumFC/ps aYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=j10MBxPavp973rCVehH8eqME/mHuJFVsbejVLw/uZ1o=; b=TkaBkiV2bp+qa6CxDZT7jKgAB3DOlyPFaIV33vwzNST0dTUDOTzptd52ZdDR8gnI57 LUGf7iw3zT5ZNEmfiUwkZi+ADniNefNNE+hGiOkNoN0NBXY3nJV/md4EmkcC6uriPOG4 qNkHOBJSOMJpavTAdc3Nq2Mo76JWzBK4VrLj8MzfKpZA4Atg3LeImUsLnGGpEM24cJyc qoybqdHGXoskPgAmxKy/NZ0AjfK0hkGV17mOH9d1XJ9WQ9GIndAZCAkOpCzLs9Sh67jy lzljrl7eF9KcEKpx1OPallvfBkJxESEILBaaBShGPeQ7n/89W5oK/4dCqlDaMBH+g+Xq 9BuQ== X-Gm-Message-State: AOAM531HqYMZrphi3/D0z9Ht0Xd8H/5H9u9zPDxLyksbYAc/3J1sH0x5 mlwX5JkT/+0OCEaUphHisHGifA== X-Google-Smtp-Source: ABdhPJzS3MdJAcPJHwP0ndkMvcbYOvHU9lPuESCiVcd1npUM+NI7qRNbu5hJzqcwFivorcTk+2yCMQ== X-Received: by 2002:aca:b909:: with SMTP id j9mr9984871oif.1.1632351374903; Wed, 22 Sep 2021 15:56:14 -0700 (PDT) Received: from ripper (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id y11sm877508oof.32.2021.09.22.15.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 15:56:14 -0700 (PDT) Date: Wed, 22 Sep 2021 15:56:55 -0700 From: Bjorn Andersson To: Vladimir Zapolskiy Cc: Andy Gross , Kishon Vijay Abraham I , Vinod Koul , Vivek Gautam , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org Subject: Re: [PATCH] phy: qcom-qusb2: Fix a memory leak on probe Message-ID: References: <20210922221613.2115038-1-vladimir.zapolskiy@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210922221613.2115038-1-vladimir.zapolskiy@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210922_155616_612344_5E3EDFA0 X-CRM114-Status: GOOD ( 16.24 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org On Wed 22 Sep 15:16 PDT 2021, Vladimir Zapolskiy wrote: > On success nvmem_cell_read() returns a pointer to a dynamically allocated > buffer, and therefore it shall be freed after usage. > > The issue is reported by kmemleak: > > # cat /sys/kernel/debug/kmemleak > unreferenced object 0xffff3b3803e4b280 (size 128): > comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [<000000007739afdc>] __kmalloc+0x27c/0x41c > [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0 > [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc > [<00000000fc81fcfa>] phy_init+0x70/0x110 > [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234 > [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990 > [<000000001965faf9>] dwc3_probe+0x4f4/0x730 > [<000000002f7617ca>] platform_probe+0x74/0xf0 > [<00000000a2576cac>] really_probe+0xc4/0x470 > [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190 > [<00000000130db71f>] driver_probe_device+0x48/0x110 > [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140 > [<00000000e5812ff7>] bus_for_each_drv+0x84/0xe0 > [<00000000f4bac574>] __device_attach+0xe4/0x1c0 > [<00000000d3beb631>] device_initial_probe+0x20/0x30 > [<000000008019b9db>] bus_probe_device+0xa4/0xb0 > > Fixes: 0b56e9a7e835 ("phy: Group vendor specific phy drivers") > Signed-off-by: Vladimir Zapolskiy > --- > drivers/phy/qualcomm/phy-qcom-qusb2.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c > index 3c1d3b71c825..061665ba8ef7 100644 > --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c > +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c > @@ -589,6 +589,8 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy) > qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2], > val[0] << HSTX_TRIM_SHIFT, > HSTX_TRIM_MASK); > + > + kfree(val); Nice catch, here's my: Reviewed-by: Bjorn Andersson That said, do you think we could replace the nvmem_cell_read() with a call to nvmem_cell_read_u8() to avoid the need to clean it up instead? Regards, Bjorn > } > > static int qusb2_phy_set_mode(struct phy *phy, > -- > 2.33.0 > -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy