From nobody Thu Oct 9 10:06:05 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 94F532F533D for ; Wed, 18 Jun 2025 07:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750232220; cv=none; b=YLsHIeFy7MXCu3QgG2S2+M38OMYKTOhL9r2bLtGC9GgfuYbN375ovLNCnZ8ctRU5FPd0mgNNQ3uJFJf3J4g75UctDmpkN4Oe0RtNjA0fVD/ocqKJjNP8SEw9foqdCQ0IhwbWuIpKPC4OL1zaz7W8sw4o+j7mc7SjB0CLo5VsfPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750232220; c=relaxed/simple; bh=WkRs/TboFDX8xfzfGINehv8lcvkeaBoDHGvUNBlrxXw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JfF8KU2wUe89K38e9kXP+TDuS3iJmBr3Fogxtms1guAeZPomso+oSb44PSHj32+p4fwgGgKKFd2ZK1pcCbiGKB7vA7X0onS7Ixul6iXo+1iu+x+FLwZPOMLWqrJFRzGyF72Wa4FJFJvzqVsgfA4YBw2mgBHy7lwvRGV6CfJAWBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LTAl8TCO; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LTAl8TCO" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3a52878d37aso1215253f8f.2 for ; Wed, 18 Jun 2025 00:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1750232217; x=1750837017; 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=XZXBxt0cc6L0naAoZJZAGNT6TJUcn+mtDHZVLEqs+No=; b=LTAl8TCOxh1uOwiGrB8LrimzoI0hpWdZKIcoOk/sdaTPZ0m/KK4oTpy9EpyCWySKaO rVguNPBlRlEtticcaia4kU44Szw1+PNwbceUGu41zmDdX92XKLgqneouNgIZuk/9W4zw NTMM57h7Sxi7GLnoAhaEKEzoFykIglwEYCWzxDa/z6R6PuoDHd2WUOLW2i0WZEPwI9cY wst0pI0mBX52ouJd0klX+SEJbZQ7WouC+oq4sp1HKqP+VBmKNkyQgDhIxT9NxiGTsAeA bUVoxDpNRUSALO5U0AWUUIJ+oYFwjhsUsUY2pJoZJja+sW1b52vCUvEEUl6vXT9ue0xe IkJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750232217; x=1750837017; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XZXBxt0cc6L0naAoZJZAGNT6TJUcn+mtDHZVLEqs+No=; b=CVy2zWk3Ji/pYyd73nXlEMGj0D75ErhHXqDGISV1i3575fp9O7m0cp5ZPmkE6aHkg9 +hTGxL5AOHDwHgmgyDI4zo5Ws9tTc3erFEbw1g3te72IkqV1VV/lY2bgVTABoMQxNq5Q lw6Bm5v5i27kyVItPU6StqJrwlk7rAfWcPCFqrIXGlSrzRzrg0zgIu2gKELWhRzCvqHF YPuSn1n2Y0B5wGnk9u6gJVYMr6KdezR+VNPVm/qT+suUwHk+/RQAPT3rjj2B6mVKVWl+ YT8belOLKi4ESofN/bi0bsPL0SG1WoskxQZo2bPuqVBpOwdnadAH/W/zaPTMb9Dd9GIy Gb7g== X-Forwarded-Encrypted: i=1; AJvYcCUHq9JEdR74SYT4fJ6FkZr3kA7zu6Vuf58LFTlJXdMkoUstSRzS4rTH5GhdcAlDVEqlmNdUwjPniK8cJpw=@vger.kernel.org X-Gm-Message-State: AOJu0YwfhnwNxBK0HGfZmU9OLuUeNmX4HzA3E/UC+ZEG+AsDJqjP/+6f zIyb2LeXPgWOnjma/gNuuM9PHxm09/JyBJnGAQkfDyHGZb+l5ebc9XP/o1qzY2Adsm4= X-Gm-Gg: ASbGncsK0KPZ1ZSXAmb9VUbhZY7+WSX/tkCvYOoykdemylSzykQPK7sSGHzCtR58Won cJ77XaOkfn3kWC0VjblIPKd15drAW/PyO5hDM/MCmBcWu6ObJnRFbxmhO9O9c/qa/cEnZOoHuC4 trrzHZorDv6n9SBYj4hjKEfK06rYSLWuhOxWBePl0/9SXGZjZrG7g2EZ+iRiiVEeP7rkWpRzv23 E/0EQpcTHnux8dqK9S7cHAlmbefsVh1s1vEXp0lHeQwwEd2PTNKBNfPjuuwfM+ieXAos0HsyHDt vh8u8ymQBz/W05zAVNabQ8/ACcrV3Jz3i/8GyUBuMZfD/jKoIY06i78dGecR/Cat/Alj+Qg0iHn 4fhli0T+A X-Google-Smtp-Source: AGHT+IGzdx4bFzKCr1o8dRWdVSdkAmLcmC90spjSihYQwSyc0weZmyPLolTCTmYgiIecY8zC3ErPWA== X-Received: by 2002:a05:600c:1d0d:b0:43b:ca39:a9b8 with SMTP id 5b1f17b1804b1-4533ca48dffmr58906925e9.2.1750232216922; Wed, 18 Jun 2025 00:36:56 -0700 (PDT) Received: from kuoka.. ([178.197.223.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532de8f2e0sm195792835e9.8.2025.06.18.00.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 00:36:56 -0700 (PDT) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Vincent Cuissard , Samuel Ortiz , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Greg KH , Linus Torvalds , stable@vger.kernel.org Subject: [PATCH] NFC: nci: uart: Set tty->disc_data only in success path Date: Wed, 18 Jun 2025 09:36:50 +0200 Message-ID: <20250618073649.25049-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1821; i=krzysztof.kozlowski@linaro.org; h=from:subject; bh=WkRs/TboFDX8xfzfGINehv8lcvkeaBoDHGvUNBlrxXw=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBoUmyR9Sy/6+NxZF35Vz8mGEq+q31qkerrdCl1S kIPLmllOdKJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCaFJskQAKCRDBN2bmhouD 13omD/4zhyiDc3yVsBfIujWpgDnnQ/l3ePHvdbts5xY9N05fFjRhLNIv9Z/PMQfCL5sWiYJxZZo 9X1IAcKsu7TItxoN+Kx8Ah6IruEbidB02Nyt/C9TxaWVzETWDWvDCUQzwpM1H1lVNmQPojXIwgU wZaoSbr66Qlgyygzsh8npVA48SkBzSucYhEpPfGVP2+5MIMEJthHwGaoUyss0tfJAGD0XA6VMl7 Ad8vdIwkI0ZCY3kkpnHxYMsWSYFzJAZmRRvrJC4B2+rQHdctXwwfSvjBrlTWMV9r6tt5c3EBk/P xnmPGhzHSXp11rasBPlmwmubeC4879dQdbewqlIVj5ymyfSVLqOdvzoXrqBwoXajhxUDS78SN/y iEs/8phFmc98F5kLrJ2cB9zI5hoSD/VmM50fHfgjuVpSjF+fQqnRl4D+wuj6rgvmpmL5otgI50O eUC1qmE30Almsx/ey2bbBlVsHeSvC41jwzdMK+Y93qjIoZdqaqVc4AztnwPFk3pCw3f/dnpCn8Y YYleGNGUgPIcPC5sKa/McvfOHO7VHEHTXkOfuTdqk5d+pqc6XesjhE3YKNTYLyO0rWb70akwz4c l9Ey/IYMak4UQ0W6IgEV1JIL/PHA6xqIs2jbjimYqngW79+VBvS77zkrz4B4ZtSNvuzp2a59Ej7 bsaAbyuHHDH8vfQ== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Setting tty->disc_data before opening the NCI device means we need to clean it up on error paths. This also opens some short window if device starts sending data, even before NCIUARTSETDRIVER IOCTL succeeded (broken hardware?). Close the window by exposing tty->disc_data only on the success path, when opening of the NCI device and try_module_get() succeeds. The code differs in error path in one aspect: tty->disc_data won't be ever assigned thus NULL-ified. This however should not be relevant difference, because of "tty->disc_data=3DNULL" in nci_uart_tty_open(). Cc: Greg KH Cc: Linus Torvalds Cc: Paolo Abeni Cc: Jakub Kicinski Fixes: 9961127d4bce ("NFC: nci: add generic uart support") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Greg Kroah-Hartman --- net/nfc/nci/uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c index ed1508a9e093..aab107727f18 100644 --- a/net/nfc/nci/uart.c +++ b/net/nfc/nci/uart.c @@ -119,22 +119,22 @@ static int nci_uart_set_driver(struct tty_struct *tty= , unsigned int driver) =20 memcpy(nu, nci_uart_drivers[driver], sizeof(struct nci_uart)); nu->tty =3D tty; - tty->disc_data =3D nu; skb_queue_head_init(&nu->tx_q); INIT_WORK(&nu->write_work, nci_uart_write_work); spin_lock_init(&nu->rx_lock); =20 ret =3D nu->ops.open(nu); if (ret) { - tty->disc_data =3D NULL; kfree(nu); + return ret; } else if (!try_module_get(nu->owner)) { nu->ops.close(nu); - tty->disc_data =3D NULL; kfree(nu); return -ENOENT; } - return ret; + tty->disc_data =3D nu; + + return 0; } =20 /* ------ LDISC part ------ */ --=20 2.45.2