From patchwork Tue Sep 14 09:22:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 510922 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1359855jao; Tue, 14 Sep 2021 02:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+LFThgTubTtV7/4s8a58AiaTD54BhQUvpqXVub4virRCWvyJhopMqDg8AjmI0xKvi9+tT X-Received: by 2002:a17:906:2f15:: with SMTP id v21mr17619279eji.444.1631611353005; Tue, 14 Sep 2021 02:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631611353; cv=none; d=google.com; s=arc-20160816; b=DnHgQqJyT+lEBIzdGmD0YRFtRQW4CrR6tun+WujnvmMbqIgvuby7sFWe4JmpAej8ma ZvW37+edFZ5BlBzn+9tfl5kOQ3n8gu6SH8EvJGeQp1xp+5A9Vcb6YjRsivT+BGdyBtfv 4YSNhFE/HBg+YjJzq/V7M/Rk4FMM3djy3GOFYbuwvYAUrUdZecFyaOeATjLT8xEq6S8n YznVUUIcnA4v8nygY25yoSnma3Cpk1cSHTaxJTkjfbmdwpe916udAX3JdEPnDPHm3BXw Q0hw9gQ9mVh1NgF0cLx6x2Io4EvqS6B8VUXgGKObc+7RlNeUjn9itgcbw8Ni7ePNJMbt Vjnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=cB3SFW2TbyjnhTTrE3Gw+3s8XVu1+IHGM7eNQeJ4Ffo=; b=H5b254F4mSmT1SW08xRrzy3XQDSs2skhXtuLCp4CxkUM9B75DSmWFEG5+oS28I2GV8 9tw5pKnroFYeWGJtmzTJ5zBnN7U/ZYG1PZIsb7MfJr4JKujjKQfpB6BNTgg9Pgiw0sOa 1WpyUeT4qqJx8r7tzUF9zv+msVo6i6ipiy0wxJ8lBZ2mAghRaPVgFxF7SED0RxcUtISE 5ORmauGAojK4kASAthsGb8Lw/r+uVJCADo/sevxgHH1lixqjNCTd7HUh/tqsgrYlvFnU jd4cCwUsRYGatgtB1PtMMHkN2EChhhkhrAiNFd2TJde+fYdiYi86N9mn61HxN8SglQhy iMOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yObLhpnS; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-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. [23.128.96.18]) by mx.google.com with ESMTP id bo16si9751782edb.144.2021.09.14.02.22.32 for ; Tue, 14 Sep 2021 02:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yObLhpnS; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-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 S230219AbhINJXt (ORCPT ); Tue, 14 Sep 2021 05:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbhINJXs (ORCPT ); Tue, 14 Sep 2021 05:23:48 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB5FC061574 for ; Tue, 14 Sep 2021 02:22:31 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id w29so18285431wra.8 for ; Tue, 14 Sep 2021 02:22:31 -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=cB3SFW2TbyjnhTTrE3Gw+3s8XVu1+IHGM7eNQeJ4Ffo=; b=yObLhpnSD42+GQIkt8UzLMbYH0wUIX/Qsa0sHlxnsX2a6lCRi2T3pjnP6ylSEK0yJ3 9HEeafmyGngxXsz0OE/+/lfSL1TAvR9Oy7nTZ2VS7wnHbM3FqlnZgMAmqYrHuwa5AF6D gJ61PXj6JyqwEwgN3FHa2HW7n191IRrUNf8kgPM4zPuJCrpgtPVjML9EEzrM+Z1BFJBS mvCJ6xIRFSlxuMWvg1LBuZJFpxOvmRxU/ESOtoMEwq17wYPRI1P8EHlh09PNk02lb6ce D7wffZg7MrNeTUMMQQhpBzIyYZtIQzEW+fnuXJugHWvdZkX9yUA1Gn2Empvto1i9z80G f4Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cB3SFW2TbyjnhTTrE3Gw+3s8XVu1+IHGM7eNQeJ4Ffo=; b=GJEn/kNeKvcO2jY89F5c9DpKogCKXBpAkIz5rVm2XirVSZMw8DA/eZxNbHApUUKb1F UDtn72+WzPfQn1uR++uvQYpUZle5HBxu9eZDj6jzoTJ/VnvpgOvR/EN8ga8L5LpYsizZ LL4ed2HwW/Vy1WPalvHRqP7vYdQIv26c2IyTYnZszp6TmvlR/m7yu9B1wRG79KgosBwX FtD2+j8rbZfQ6TzYdPuzMjEBQC1IgpEmyJNqJO9zz7pVietf9JPAhUUcAxP5SGMVO/LZ v5m5e/wsbr18WmHxUkxjmpMEhlhDJorZh7LUHhxiSeYw67uuRrYB24KAIFJ6pzSnjwjy 9wIQ== X-Gm-Message-State: AOAM530XVofueG/AUfufsJQsFodYKHysmWAep/YpmwV2iEG9/ZnviKoV a26D3EQY6EWSqNoPxAepNJCkPQ== X-Received: by 2002:adf:8b43:: with SMTP id v3mr18138405wra.248.1631611349959; Tue, 14 Sep 2021 02:22:29 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id p4sm544765wmg.16.2021.09.14.02.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 02:22:29 -0700 (PDT) From: Srinivas Kandagatla To: alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: draviv@codeaurora.org, sthumma@codeaurora.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, Srinivas Kandagatla Subject: [PATCH] scsi: ufs: ufshcd-pltfrm: fix memory leak due to probe defer Date: Tue, 14 Sep 2021 10:22:14 +0100 Message-Id: <20210914092214.6468-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org UFS drivers that probe defer will endup leaking memory allocated for clk and regulator names via kstrdup because the structure that is holding this memory is allocated via devm_* variants which will be freed during probe defer but the names are never freed. Use same devm_* variant of kstrdup to free the memory allocated to name when driver probe defers. Kmemleak found around 11 leaks on Qualcomm Dragon Board RB5: unreferenced object 0xffff66f243fb2c00 (size 128): comm "kworker/u16:0", pid 7, jiffies 4294893319 (age 94.848s) hex dump (first 32 bytes): 63 6f 72 65 5f 63 6c 6b 00 76 69 72 74 75 61 6c core_clk.virtual 2f 77 6f 72 6b 71 75 65 75 65 2f 73 63 73 69 5f /workqueue/scsi_ backtrace: [<000000006f788cd1>] slab_post_alloc_hook+0x88/0x410 [<00000000cfd1372b>] __kmalloc_track_caller+0x138/0x230 [<00000000a92ab17b>] kstrdup+0xb0/0x110 [<0000000037263ab6>] ufshcd_pltfrm_init+0x1a8/0x500 [<00000000a20a5caa>] ufs_qcom_probe+0x20/0x58 [<00000000a5e43067>] platform_probe+0x6c/0x118 [<00000000ef686e3f>] really_probe+0xc4/0x330 [<000000005b18792c>] __driver_probe_device+0x88/0x118 [<00000000a5d295e8>] driver_probe_device+0x44/0x158 [<000000007e83f58d>] __device_attach_driver+0xb4/0x128 [<000000004bfa4470>] bus_for_each_drv+0x68/0xd0 [<00000000b89a83bc>] __device_attach+0xec/0x170 [<00000000ada2beea>] device_initial_probe+0x14/0x20 [<0000000079921612>] bus_probe_device+0x9c/0xa8 [<00000000d268bf7c>] deferred_probe_work_func+0x90/0xd0 [<000000009ef64bfa>] process_one_work+0x29c/0x788 unreferenced object 0xffff66f243fb2c80 (size 128): comm "kworker/u16:0", pid 7, jiffies 4294893319 (age 94.848s) hex dump (first 32 bytes): 62 75 73 5f 61 67 67 72 5f 63 6c 6b 00 00 00 00 bus_aggr_clk.... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ with this patch no memory leaks are reported. Fixes: aa4976130934 ("ufs: Add regulator enable support") Fixes: c6e79dacd86f ("ufs: Add clock initialization support") Signed-off-by: Srinivas Kandagatla --- drivers/scsi/ufs/ufshcd-pltfrm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index 8859c13f4e09..eaeae83b999f 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -91,7 +91,7 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba) clki->min_freq = clkfreq[i]; clki->max_freq = clkfreq[i+1]; - clki->name = kstrdup(name, GFP_KERNEL); + clki->name = devm_kstrdup(dev, name, GFP_KERNEL); if (!strcmp(name, "ref_clk")) clki->keep_link_active = true; dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz", @@ -126,7 +126,7 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name, if (!vreg) return -ENOMEM; - vreg->name = kstrdup(name, GFP_KERNEL); + vreg->name = devm_kstrdup(dev, name, GFP_KERNEL); snprintf(prop_name, MAX_PROP_SIZE, "%s-max-microamp", name); if (of_property_read_u32(np, prop_name, &vreg->max_uA)) {