From nobody Sat Jun 20 11:50:47 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 4C64D3E556B for ; Wed, 15 Apr 2026 17:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776274617; cv=none; b=Jzj1hmHOGaMAAJZJfQVNvVeDmGjfFCnXtZO5PXizpLpi1mYYHIBbu7sB/ncb8DlHNNVMrKmsYhIfhKKpXjzOVVWL5AUV6B0wN0dxpkrWAPkWt7K1okYPAdlBegMsehIhAbVmWrakXUW8WvLKuPD1H+ok+OlfAlnyLB4f6oWnDak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776274617; c=relaxed/simple; bh=bA0YOmRdTf8lHrEqsCcgLCiC6Qt/bbKa5pnwwqjZpqw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ixiotwqg2Q7eVIFGcCuDJ+xi8mLjHS14rwKi168Py2Qbv0+9UUENybHelHkh391lN7XoiP0ZSaEx8oLfI3lMGgTOOj1mqPYnD/qXPP5GxY0dMfntAYZo59BK9sTmDVWeF08RecpPXT7RqvSPZcPVy8niGS3H0pS94XqyeTVCV30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vjx5rT3R; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vjx5rT3R" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-82f138a6d5aso2446017b3a.0 for ; Wed, 15 Apr 2026 10:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776274614; x=1776879414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=H/+TVnN1GkzXWBQnr1PT9tBUGuFu3f8nhPggRnsX4wE=; b=Vjx5rT3Rcl7o62BI1MYke7TIn6RnkyEJPSkdvv4lD94IjTGJfYV5hJeRK+V2lGXi83 7GaR9vhglsUWWr3hABBQChM+DHh0B+u/9IP5OWgQoUPRIgxgDi7xPRjKYVOu6fgdpcc5 JIub/MjkA4mky32jHZG++doLfRyP5hPTX/oBTmZbCUzxWE2rYxhFPe1vT/LKMZWeJc1B BlE4HkXSJXyoa/5VdI+wwIR4G47bmGgHC0vGdoigmSBmdgA6XVsSEiLWTxTMMREhzZzJ XMfGaD6nKrrWgdiLydgwYaqwq4dCt1kpTo9G4xvcpy/G3WmV+zw9ilK2fR2kYrxESUii w0Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776274614; x=1776879414; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=H/+TVnN1GkzXWBQnr1PT9tBUGuFu3f8nhPggRnsX4wE=; b=dTJLJoQv7GL6Yb5fMWdm2YypwdvW8kpvx5oIMzRofQFFtkgdDnCV/7Y0TvXRTh4tbo KEPxClIyd2yeZEjggnzHAcLuq7Vg9mfv0bZZ4k1c5draguwUijy2wOskeQPAxLn1lkjh BJn4W8xkW4Rq0806n1XsoCLyZBDK0fXasOsCzEHtz1udsyKOaDd/PLG0n0+Irjim3wrx 2n3EFJ2PfYI4KQeKUehpEx9xGsLAdeFU6kOb3a5CzkQe7ppbRkSpCUBZ7lCgZT8dwoA2 xK9nQavq6dv7XNNc5f+6ff8j382S/fJkc8VqMK1BjWMMrAmUi4l9GR4zXXgCJqHa86Cv xZOw== X-Forwarded-Encrypted: i=1; AFNElJ96Wn5Z3PlBUjw9U5qnBKdn+UGP0BzE6+z0msC0DFCC2qG45Qw/pBZjPFlFs1txCS4jyqGf4K2KMxPGZJ8=@vger.kernel.org X-Gm-Message-State: AOJu0YxoZn0E19NLXdS5DWhnwJ40MwHue6tliByBZ8C04EhCbEn37rHj QvvrI8E/lS+2GDSYJ+taEgikzIsAkHyHWaXhbNolE0NyDZ61QuXHxWKd X-Gm-Gg: AeBDieu/utP39KG+tr8cnAzV19pNSv/etxqCfLR07xJBmVlAKGS0lq6H8AH1O8uwEM6 VUrX76g8QjAdOi0uMujMFIIaGMxrk6kkOwTfv4Bp3JckmHWec8yUppqFYp+NVROB3IlH487Qsdn yvOXht2D86V5hxzb6qpxHWo2IgvBZ/2dOqSq42ED31GxezyHj1Aji1O/x4qwMfzYeG+wDskUyz8 yywGlzB7xlNQua5N8IHT1xY4bPrEmm9yn4TE5BNhF6lR3YFfvYRT4hOm7GKK+cqzFzmBXyVaX4P vMjjNQXmT1mv5NgO+HFYp83ndZc9JHhMpjRAV7fUAHFg5XV66kPvv/vrjqvR5QAz/AH1/5avA1J dB0RNrkMKoAXAuoIxo9YWlpyv9CZG9h3Rf+W46AmEtdW3Eg1yaqXDCDiqVkPzMqqeoSRq3Ex5ma q4+QCN2BsDYiorxuudqk/B3odQH2FdvOpJSg5z X-Received: by 2002:a05:6a00:10d1:b0:829:8cfb:df45 with SMTP id d2e1a72fcca58-82f0c29ed5dmr20427786b3a.15.1776274614586; Wed, 15 Apr 2026 10:36:54 -0700 (PDT) Received: from lgs.. ([2409:893d:1171:10e2:48dd:8f21:beaa:cec8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f6703631dsm2739863b3a.3.2026.04.15.10.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 10:36:54 -0700 (PDT) From: Guangshuo Li To: Dominik Brodowski , Guangshuo Li , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH] pcmcia: tcic: fix init_tcic() error handling Date: Thu, 16 Apr 2026 01:36:42 +0800 Message-ID: <20260415173642.3619223-1-lgs201920130244@gmail.com> X-Mailer: git-send-email 2.43.0 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 platform_device_register() fails in init_tcic(), the embedded struct device in tcic_device has already been initialized by device_initialize(), but the failure path does not drop the device reference for the current platform device: init_tcic() -> platform_device_register(&tcic_device) -> device_initialize(&tcic_device.dev) -> setup_pdev_dma_masks(&tcic_device) -> platform_device_add(&tcic_device) This leads to a reference leak when platform_device_register() fails. The reference leak was identified by a static analysis tool I developed and confirmed by manual review. While reviewing the code, I also found that init_tcic() continues to use tcic_device.dev as the parent for registered sockets even if platform device registration fails, and that the pcmcia_register_socket() failure path only unregisters the first socket instead of rolling back all previously registered sockets. Fix all of these issues by checking the return value from platform_device_register(), calling platform_device_put() on failure, stopping the initialization immediately, and properly unwinding already registered sockets and other resources on later failures. Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- drivers/pcmcia/tcic.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c index 060aed0edc65..43bda9930645 100644 --- a/drivers/pcmcia/tcic.c +++ b/drivers/pcmcia/tcic.c @@ -362,6 +362,7 @@ static int __init init_tcic(void) { int i, sock, ret =3D 0; u_int mask, scan; + bool irq_registered =3D false; =20 if (platform_driver_register(&tcic_driver)) return -1; @@ -464,8 +465,10 @@ static int __init init_tcic(void) for (i =3D 15; i > 0; i--) if ((cs_mask & (1 << i)) && (request_irq(i, tcic_interrupt, 0, "tcic", - tcic_interrupt) =3D=3D 0)) + tcic_interrupt) =3D=3D 0)) { + irq_registered =3D true; break; + } cs_irq =3D i; if (cs_irq =3D=3D 0) poll_interval =3D HZ; } @@ -486,20 +489,33 @@ static int __init init_tcic(void) /* jump start interrupt handler, if needed */ tcic_interrupt(0, NULL); =20 - platform_device_register(&tcic_device); + ret =3D platform_device_register(&tcic_device); + if (ret) { + platform_device_put(&tcic_device); + goto out_cleanup; + } =20 for (i =3D 0; i < sockets; i++) { socket_table[i].socket.ops =3D &tcic_operations; socket_table[i].socket.resource_ops =3D &pccard_nonstatic_ops; socket_table[i].socket.dev.parent =3D &tcic_device.dev; ret =3D pcmcia_register_socket(&socket_table[i].socket); - if (ret && i) - pcmcia_unregister_socket(&socket_table[0].socket); + if (ret) + goto out_unregister_sockets; } =20 return ret; =20 - return 0; +out_unregister_sockets: + while (i--) + pcmcia_unregister_socket(&socket_table[i].socket); + platform_device_unregister(&tcic_device); +out_cleanup: + if (irq_registered) + free_irq(cs_irq, tcic_interrupt); + release_region(tcic_base, 16); + platform_driver_unregister(&tcic_driver); + return ret; =20 } /* init_tcic */ =20 --=20 2.43.0