From nobody Mon Feb 9 17:23:51 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9980A1494B2 for ; Fri, 3 Jan 2025 14:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913926; cv=none; b=XYyCMVs3nKuvGuNHNQSAhUAxWctgW7QW+gSOuBpj7OEV16xcX1tMwJNpp3sQptDoDrmdaqxwWHJPeMdi0kXYW0DzsIgGFG9m+BXYZEUW0yBlybV2o6wD/r6kybUQDtiUiBiBj23dKkF8YG9+O6oA8ZrXOqGVsjb7VlLkX0EYdN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913926; c=relaxed/simple; bh=jP5wiY4Hjf6NHVox7oDrw9gPO0f53fe7WOrwgq5lWCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XlIG13K8J959QUbG7TAbIGIqZcGUGjkyrWXBw/CVeMn1oc2lEit6wZZtVhSpm/ZFuOS14nJ5Lv9sFuGyLHAEw7eiBIu1fO3Vdz3wz3tk1Bo/h69fdY2VaDnk0uFAEq3dm/TkiMV6OqL/U4JQ8kTBGzBt3UfCgGv3pRx7qLI5CtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=UT/ES1er; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="UT/ES1er" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CDE4C3F6A5 for ; Fri, 3 Jan 2025 14:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913921; bh=ZASmDFrSHCizrNYJB8JpDX9RUKYLSDAVuT6OOqcLRZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UT/ES1erHeo2uABJyJJCIY0gvapyJMuCisnnr+8UoaDDFUfu1KefgKqdAacFoezk6 GFAeENWpToxGKCdjROMWdsQglsnGMO5pxABQhUw/H0inyg3kOCRjUpG7sXQp6RrBi2 qY0dmiKuXJVrV6xq6Qsg203GitUZNuRx3C6OM7LDyYHcp9hde2JB+M5nKYalTWvKfq /PzcPj2RjMwBXMv1mAm8ssLtHZCx/O46Ic4apjMFiGStAFTFrs19UtCQ/gQTmrwID0 0Z/5IlUIGX1wHM0ShsiLe4rn0OUVNHdSDhIwQf/sRxlEGF5BnLz5tQXnTO0FUW83bu E1xYktnclSUaA== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2167141e00eso163961395ad.2 for ; Fri, 03 Jan 2025 06:18:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735913920; x=1736518720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZASmDFrSHCizrNYJB8JpDX9RUKYLSDAVuT6OOqcLRZM=; b=wECn33BTrqR3/moC9SNKE/pVodrYtJOpvl9AVj5ya4faJmL6F1RvXdQvvGpFJVN4wc DU8QzsxpW4XUEjGCsasOK76/WMsHWDxkghs7t2D3i4ax3cJyo0BEmieG/cdiY2DoIFdH k1mmG/sj41UI/krL2kKN/Do7jTJ++mihNHJPkVtG/Pt9CAyILt0PtqWNx/OpG8z1NeTM WXM1ct0Hw2H2zuD7EuCO9IZHPK6E5aOxH5oejdsRv9UeID7mk2mPcF4sCKOWkyGLP8Hy wTmRezRoOHxViHnafyXrqNwcUfr4Qx9zwddHtqbPlkkeBWmD/4psoVCMRezVBbna89fD +l5A== X-Forwarded-Encrypted: i=1; AJvYcCVpE+Jw0RJw+hN5rMW4Z2uUwH1JlzSzrKXh6PxVuQOGuF7You7TRTks/uB7vKDz2D9XVUP0h6CSYHLScgE=@vger.kernel.org X-Gm-Message-State: AOJu0YxOFXp+1jZcFhQBdJGVwyJHwlsntFgx+FDS6ggMYOZt/KzZmF14 +JM41RYom6nRYPdOg59Ahj5Uur+hPxsv0JICpb6IBz3KOsyeU9CLhibLIObeWqRZEMEjToYawC8 BdZ1ZCZrPYMsQCpER4bQd7bd0mdtTh+dV9hfm3k1t2VrivqS2j88YsvhVRF9P2PgXYWloi/PB8Y gaKMR/6t+TpA== X-Gm-Gg: ASbGnct0XNA1EJgEAlfIgzLiDjxfLemh5aKqy980jZhjPQiFL1nHHi9CJ4R2qKKHZkr LG7T5Sytc05J+pyXDnYPJRZCmrNTnyP4y/5wCDo7Naxy+2gOywQW83pGVLakA8wYxNH5AAvaC36 9+fTCrqCQoQZiHFDQmYaXmO5FdVxFtRJqioZRZLoU5vdVe/JBq/CkqEPOTu1zt/8xhhxJ7TvEtx sJxg0xl9Gdcgy7IhD3sYQzwgl7TE3N+yivZx/Ao7puSX6UIqgpjlXcHyQ== X-Received: by 2002:a05:6a20:7f87:b0:1d9:3b81:cdd3 with SMTP id adf61e73a8af0-1e5e0446330mr75040973637.1.1735913920284; Fri, 03 Jan 2025 06:18:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm3Kja89gSgoWB37SsFC82gysqHLLpOOCP6TvpCB3iQy7oMAN6+NUKnLxb5xzVfUWyR/mfBQ== X-Received: by 2002:a05:6a20:7f87:b0:1d9:3b81:cdd3 with SMTP id adf61e73a8af0-1e5e0446330mr75040939637.1.1735913919933; Fri, 03 Jan 2025 06:18:39 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd7b0sm15502908b3a.139.2025.01.03.06.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:18:39 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] gpio: virtuser: fix missing lookup table cleanups Date: Fri, 3 Jan 2025 23:18:26 +0900 Message-ID: <20250103141829.430662-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103141829.430662-1-koichiro.den@canonical.com> References: <20250103141829.430662-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a virtuser device is created via configfs and the probe fails due to an incorrect lookup table, the table is not removed. This prevents subsequent probe attempts from succeeding, even if the issue is corrected, unless the device is released. Additionally, cleanup is also needed in the less likely case of platform_device_register_full() failure. Besides, a consistent memory leak in lookup_table->dev_id was spotted using kmemleak by toggling the live state between 0 and 1 with a correct lookup table. Introduce gpio_virtuser_remove_lookup_table() as the counterpart to the existing gpio_virtuser_make_lookup_table() and call it from all necessary points to ensure proper cleanup. Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GP= IO API") Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 91b6352c957c..e89b1239b635 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1439,6 +1439,15 @@ gpio_virtuser_make_lookup_table(struct gpio_virtuser= _device *dev) return 0; } =20 +static void +gpio_virtuser_remove_lookup_table(struct gpio_virtuser_device *dev) +{ + gpiod_remove_lookup_table(dev->lookup_table); + kfree(dev->lookup_table->dev_id); + kfree(dev->lookup_table); + dev->lookup_table =3D NULL; +} + static struct fwnode_handle * gpio_virtuser_make_device_swnode(struct gpio_virtuser_device *dev) { @@ -1487,10 +1496,8 @@ gpio_virtuser_device_activate(struct gpio_virtuser_d= evice *dev) pdevinfo.fwnode =3D swnode; =20 ret =3D gpio_virtuser_make_lookup_table(dev); - if (ret) { - fwnode_remove_software_node(swnode); - return ret; - } + if (ret) + goto err_remove_swnode; =20 reinit_completion(&dev->probe_completion); dev->driver_bound =3D false; @@ -1498,23 +1505,31 @@ gpio_virtuser_device_activate(struct gpio_virtuser_= device *dev) =20 pdev =3D platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { + ret =3D PTR_ERR(pdev); bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - fwnode_remove_software_node(swnode); - return PTR_ERR(pdev); + goto err_remove_lookup_table; } =20 wait_for_completion(&dev->probe_completion); bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); =20 if (!dev->driver_bound) { - platform_device_unregister(pdev); - fwnode_remove_software_node(swnode); - return -ENXIO; + ret =3D -ENXIO; + goto err_unregister_pdev; } =20 dev->pdev =3D pdev; =20 return 0; + +err_unregister_pdev: + platform_device_unregister(pdev); +err_remove_lookup_table: + gpio_virtuser_remove_lookup_table(dev); +err_remove_swnode: + fwnode_remove_software_node(swnode); + + return ret; } =20 static void @@ -1526,10 +1541,9 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser= _device *dev) =20 swnode =3D dev_fwnode(&dev->pdev->dev); platform_device_unregister(dev->pdev); + gpio_virtuser_remove_lookup_table(dev); fwnode_remove_software_node(swnode); dev->pdev =3D NULL; - gpiod_remove_lookup_table(dev->lookup_table); - kfree(dev->lookup_table); } =20 static ssize_t --=20 2.43.0