From nobody Sun Oct 5 00:12:24 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 839452E5B23 for ; Tue, 12 Aug 2025 08:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754987245; cv=none; b=LZygNOof/xgVw0T/t8VzF2dp1D6r/8UcJzMshgQ490keQIyp+53VBP0BvbuKm4VtLnU4nai6s54x8Bh24n5SQF7VmM6xlPxyv4Td3o7P5vTXqasR8k+9zC03nIDuDBiFCGJGLj3xmNXjLOvUSgP+lQjFYKfM95rMjMNqpAKJlJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754987245; c=relaxed/simple; bh=8LckYYbv7wEiVDCoVOTbwt+nYJz1zV0AkW539eEIzwQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HHQaw/8+0WPFq3SyFK7Ua7HJK+fvhQwtISJpkQsItni98iBOmACHAlXSq+CdmDb7oya53s4A2UQ1n+4LMm9Lo8jp/F6L97fporkYTD8+04TL0JmqONfVWaIaDqVS5vu9/PpJt4K40OGZ66/YmMVvTIw10aUYmffqVTAbCwzfiKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=f8YcOLuJ; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="f8YcOLuJ" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-455fdfb5d04so26171005e9.2 for ; Tue, 12 Aug 2025 01:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1754987241; x=1755592041; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rcnhHIb6eNEwdjxZYrigpF4SQxNgYqLi3t6s+DqhmIc=; b=f8YcOLuJWaGoKO3ukED1ZsheFdnSRu5+oB9sD73V5nMByxiz15V+e5dLXCdtR3zPoS 5WdQLsn/RoE4Mjif/R0dCQ34iZ8BKbRiQXikHc0J5IiQEJJYO4p8YSw2BbuMIZrMzXjt DqOvaaSHYgA7cW/6YDepzSUcmIJuMLT5jf8/TbhJzss7bTiJ8BSJ5BRYCBoRnTRjqlzv Da387BNwVhnn4ee3QZhR9gDlVpf5IKqxYq2GW5Kh5LlSPy9X8SOnB0c/tRl5ANUL3AE3 yi0EDPFEU+okfgwI7gt8DnkIXUrQEmjLUPBSCKT2Iio0XQKGY/EOHy1vG/WzadL2km1P UaZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754987241; x=1755592041; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rcnhHIb6eNEwdjxZYrigpF4SQxNgYqLi3t6s+DqhmIc=; b=qlqTa4GHXqxm9/W9ddtwygn/waoHw5WNrlCdHMSoqB4t3aQADEGzKGt3td8grFFIrt ec23As8OQHCB4vTIzLutJPfnEhUFE3Q9ln9CfP/y/8Rpo+DLAtTKrnu4rT3Ulh3vsTGO 0se1JrjwPeXzTUq2EsruXsdECcC55gEk17cP/0yghnkW+ljgONRKdxSgm7c8rvFEc9nb t19eOGeEay70A4bVf/gQG9QjSzNfnDKq5iq5EDMbZSEWnPqpt4VHh30QB9llJnP0NYoa 20VJT8CHmB8ri3LK8hJGuFKbFsg0GOmgbX6J4ODg52i1dQ7d7z0bm8H7GVEeTiD+5xJn wWhg== X-Forwarded-Encrypted: i=1; AJvYcCX7l0Ej5TRUKbTaCcG3Ibos+8iJX6JSIfVu57vgbx4tVuZigZor5TNlQFVMH0mKgWoaKtsLTFM7Z6wjZzw=@vger.kernel.org X-Gm-Message-State: AOJu0YxgQufCD0wmSh6yorseQ4x6vJz59p8IkmBFcpTO4lqhtg8Vqb8i FPI7PrXdu7P/YLDexyt1JudQj6DMui/19meZJBKvL+ripN/t0n0YTIbZblNk2Zl2KHc= X-Gm-Gg: ASbGncv7W8evrp79MYDl0IlCg8pqKuJB8zZbPRlRpuE8yM9RsklBvnQPXrY9spd/Buu W74RxjrhfSEetlF/gGhN9a+A0O4kytRTR53UEBwLzJUgsqNMxkUIEHoghSfOThCMsLib9WbPIxN mvPOfv+IcjM6TxgAERD3vglS5vSHGSIbL0FCz/gse4FWwzuEmHH7H1Xdsq7QOgPDjfMt4OASNbU GNprkyyH8vlA2zeAAsZeZMP81wfLOOYfxluvad5NfrvLWT5xwu8a6RvlT40HLFTWvyQ+Np5fhK9 sT4cARsg+/rwtPx/Whn0bGKpmFkQp/yD2IluCrIpW8IrTufnhfmHp+32zMI51ZLCabUgxMH3r3j iSPlvgARYePZlhdE= X-Google-Smtp-Source: AGHT+IE8fEgiEn9lwBjUv2uob+aBCzOy3kH39g3JVI8xm0JYVluln+IusGsEv24A0i5bbeOMk/kDAw== X-Received: by 2002:a05:600c:4f91:b0:456:29da:bb25 with SMTP id 5b1f17b1804b1-45a10bf510dmr21937425e9.19.1754987240452; Tue, 12 Aug 2025 01:27:20 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:16c8:50:27fe:4d94]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3b9386sm43549423f8f.18.2025.08.12.01.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 01:27:20 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 12 Aug 2025 10:27:06 +0200 Subject: [PATCH v4 07/15] pinctrl: keembay: release allocated memory in detach path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250812-pinctrl-gpio-pinfuncs-v4-7-bb3906c55e64@linaro.org> References: <20250812-pinctrl-gpio-pinfuncs-v4-0-bb3906c55e64@linaro.org> In-Reply-To: <20250812-pinctrl-gpio-pinfuncs-v4-0-bb3906c55e64@linaro.org> To: Linus Walleij , Bjorn Andersson , Konrad Dybcio , Alexey Klimov , Lorenzo Bianconi , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno , Paul Cercueil , Kees Cook , Andy Shevchenko , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Dong Aisheng , Fabio Estevam , Shawn Guo , Jacky Bai , Pengutronix Kernel Team , NXP S32 Linux Team , Sascha Hauer , Tony Lindgren , Haojian Zhuang , Geert Uytterhoeven , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, imx@lists.linux.dev, linux-omap@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1867; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=qPaUa8oAewMMgl8vCYU8JU6h4WrDoK89nonD2PTBKh4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBomvrYc40u0edePr0EkIpRoNV/l6AhxW+gy+qoJ DRbu/5uoWyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaJr62AAKCRARpy6gFHHX cr0FEADfv+WVcmzOaStfsm70mXUw69iAKQ+QB7ceZ9BjSwzet76pU/4gtWAVho7oelV+euRBcs0 rI79EvWGS9pbM7J6fBEPxlORgTWjhZ68KXqcPbqBLiBSldQTY1ZILTMVi18urPLCWQ3mj+w+Kju 4MbUSfSaeCLqLiFFCETd7te4vFDeDMpKmDmKxpTtqBqt8ZFzShFGXV2vxVtYLR7ztkmE1QAI3u7 DzjZ7r/jkB0IfHAG0G7RyIfDdVHgRGGw/Luhe0ppGZA3Q3qJalbn0K487GB79PLQT36ptT2Ey6C kcr9rYtt9kyoaXybtesyYcENhiUdkUSP1StOc7c54IUPOjlZ6EDG7fD72/LrgzRnCtsZ/WADH0G w6u6iuLcYQdpYxtED6m7q6rfDBsuzq6tHiZ4w3rvfvjep0xGXNo6s3bwioOPlDCh7ldFD3AEAUJ Ulgn9cufPkFGzcCwVnEc0mRvdlTavOeHzjQIt77zX98T6+AGs9rBsIDvYazO+jzAIU0TRSy7QqQ 8cE/3vgeDgTOzpTxfqdUm1HKwiHEuebwYuXdr2mI50EV4MjJbX6RN0C7XWKJjcLl7Q0l7aZRt4x MzKCL1YVBkfo6txurpQA3wRqXkgDFUW6ek8GoVdzy0LtGZirWgtY2Q3RAMVsBav9S02diTip1P2 w/nGmj49yU8wsew== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Unlike all the other allocations in this driver, the memory for storing the pin function descriptions allocated with kcalloc() and later resized with krealloc() is never freed. Use devres like elsewhere to handle that. While at it - replace krealloc() with more suitable devm_krealloc_array(). Note: the logic in this module is pretty convoluted and could probably use some revisiting, we should probably be able to calculate the exact amount of memory needed in advance or even skip the allocation altogether and just add each function to the radix tree separately. Signed-off-by: Bartosz Golaszewski --- drivers/pinctrl/pinctrl-keembay.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-ke= embay.c index 60cf017498b32a9f36a1f8608e372951c2b8f12a..6aefcbc31309995ec1e235416b4= 0aab3e4a073a9 100644 --- a/drivers/pinctrl/pinctrl-keembay.c +++ b/drivers/pinctrl/pinctrl-keembay.c @@ -1603,7 +1603,8 @@ static int keembay_build_functions(struct keembay_pin= ctrl *kpc) * being part of 8 (hw maximum) globally unique muxes. */ kpc->nfuncs =3D 0; - keembay_funcs =3D kcalloc(kpc->npins * 8, sizeof(*keembay_funcs), GFP_KER= NEL); + keembay_funcs =3D devm_kcalloc(kpc->dev, kpc->npins * 8, + sizeof(*keembay_funcs), GFP_KERNEL); if (!keembay_funcs) return -ENOMEM; =20 @@ -1634,7 +1635,9 @@ static int keembay_build_functions(struct keembay_pin= ctrl *kpc) } =20 /* Reallocate memory based on actual number of functions */ - new_funcs =3D krealloc(keembay_funcs, kpc->nfuncs * sizeof(*new_funcs), G= FP_KERNEL); + new_funcs =3D devm_krealloc_array(kpc->dev, keembay_funcs, + kpc->nfuncs, sizeof(*new_funcs), + GFP_KERNEL); if (!new_funcs) { kfree(keembay_funcs); return -ENOMEM; --=20 2.48.1