From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C96EE1A76BB; Wed, 17 Sep 2025 12:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113500; cv=none; b=iT62iEj3JfU+IWPa2pu0zmqtDgDyqN2YN3euCJyBCUmgsX6rtBkc+tvgYSZeUibXYnYxSEOKeS8gm2j579G9TQc+zVylxKqcyrs2zC1H+p0Ktq0zIRvj/qhucz2rzpzRSMDJOkJr1/xewaNegF6XdI+GYp6rpH8ClHaD/3r+A7U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113500; c=relaxed/simple; bh=QwoYj3aDDr+SzIxRGvJ+fnH9sarfSDZOmXaca5C7FvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ru+Jtq/mkonYckk8AbqLINLiG4sHL3E6Rra1UQ7qOJTAdZriLMw3E6boy89frC3aB14bSJ4WDtHZACQVqef3MqGtL5C21xOk/WLe8lUu5V30hcXng87o5QIcpUA2UBJax+d4zTREJaQY1641tp8Kyw3mSpGjG6Y9vjfafbsUJLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LSUugo49; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LSUugo49" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B61EC4CEF0; Wed, 17 Sep 2025 12:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758113500; bh=QwoYj3aDDr+SzIxRGvJ+fnH9sarfSDZOmXaca5C7FvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LSUugo49rImRN1imNRgvIr6yQaK85UUUMZLW2B9htwOIT5ZgDRCUmJ11CsqxcI01W qeJJgS+HqWKshVpni9nzcD7xbn9rpvVseZglVykPFKoaPCysBFNAoSiVRcTFnoOLa8 2NB4/HejhLG0A2M9fFgtFmhRwc7pNSgX4ecrAdsc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tetsuo Handa , Oleksij Rempel , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 6.12 105/140] can: j1939: j1939_local_ecu_get(): undo increment when j1939_local_ecu_get() fails Date: Wed, 17 Sep 2025 14:34:37 +0200 Message-ID: <20250917123346.874596369@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250917123344.315037637@linuxfoundation.org> References: <20250917123344.315037637@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa [ Upstream commit 06e02da29f6f1a45fc07bd60c7eaf172dc21e334 ] Since j1939_sk_bind() and j1939_sk_release() call j1939_local_ecu_put() when J1939_SOCK_BOUND was already set, but the error handling path for j1939_sk_bind() will not set J1939_SOCK_BOUND when j1939_local_ecu_get() fails, j1939_local_ecu_get() needs to undo priv->ents[sa].nusers++ when j1939_local_ecu_get() returns an error. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Signed-off-by: Tetsuo Handa Tested-by: Oleksij Rempel Acked-by: Oleksij Rempel Link: https://patch.msgid.link/e7f80046-4ff7-4ce2-8ad8-7c3c678a42c9@I-love.SAKURA.ne.jp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/j1939/bus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c index 4866879016021..e0b966c2517cf 100644 --- a/net/can/j1939/bus.c +++ b/net/can/j1939/bus.c @@ -290,8 +290,11 @@ int j1939_local_ecu_get(struct j1939_priv *priv, name_t name, u8 sa) if (!ecu) ecu = j1939_ecu_create_locked(priv, name); err = PTR_ERR_OR_ZERO(ecu); - if (err) + if (err) { + if (j1939_address_is_unicast(sa)) + priv->ents[sa].nusers--; goto done; + } ecu->nusers++; /* TODO: do we care if ecu->addr != sa? */ -- 2.51.0