From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63F4BC433F5 for ; Sun, 9 Oct 2022 22:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232291AbiJIWmH (ORCPT ); Sun, 9 Oct 2022 18:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233521AbiJIWkW (ORCPT ); Sun, 9 Oct 2022 18:40:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB7340E22; Sun, 9 Oct 2022 15:21:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AD8E9B80DD6; Sun, 9 Oct 2022 22:21:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F17C4C433D7; Sun, 9 Oct 2022 22:21:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665354109; bh=DhWEa/UcfKTiGy4hMqg9NeiuFR50QRcBQOiIZP+6Pjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhZilrjYxSU43YN/yprRehm2rRxwZcnZJvsIK08jFfhjA3Mg74jxYQsIL0a6v5aNa /aKbAebwUGFhMn7lkKeUcfLaCQvAWDOluVf/+iEUmtz8Ex303mJ7bJ8a9UcF3GKZRO Tc/4lIJROG21a66UB/5F4HouzIoXBIoAjomfXvk4N5qQ7q5jXNh4mc1ZT5ADIhbad9 q74/3qsvk/wYJMez1Ii/+I1nMoBD6uBkTyWWOq7aDUwDzCc5DSMa+9noJWrZPOmn2B rtsqqVcOIKPrXPWWhf7422YtNDoe+6MFb6k0qDiAQ6H3HaJlnUvRYWQKWurw1H8gdf BLmoovqpGxqVA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jerry Ray , "David S . Miller" , Sasha Levin , edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, u.kleine-koenig@pengutronix.de, mkl@pengutronix.de, miquel.raynal@bootlin.com, broonie@kernel.org, bigeasy@linutronix.de, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 07/34] micrel: ksz8851: fixes struct pointer issue Date: Sun, 9 Oct 2022 18:21:01 -0400 Message-Id: <20221009222129.1218277-7-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009222129.1218277-1-sashal@kernel.org> References: <20221009222129.1218277-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jerry Ray [ Upstream commit fef5de753ff01887cfa50990532c3890fccb9338 ] Issue found during code review. This bug has no impact as long as the ks8851_net structure is the first element of the ks8851_net_spi structure. As long as the offset to the ks8851_net struct is zero, the container_of() macro is subtracting 0 and therefore no damage done. But if the ks8851_net_spi struct is ever modified such that the ks8851_net struct within it is no longer the first element of the struct, then the bug would manifest itself and cause problems. struct ks8851_net is contained within ks8851_net_spi. ks is contained within kss. kss is the priv_data of the netdev structure. Signed-off-by: Jerry Ray Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/micrel/ks8851_spi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/micrel/ks8851_spi.c b/drivers/net/ethernet/micrel/ks8851_spi.c index 4ec7f1615977..8327e7f30476 100644 --- a/drivers/net/ethernet/micrel/ks8851_spi.c +++ b/drivers/net/ethernet/micrel/ks8851_spi.c @@ -415,7 +415,8 @@ static int ks8851_probe_spi(struct spi_device *spi) spi->bits_per_word = 8; - ks = netdev_priv(netdev); + kss = netdev_priv(netdev); + ks = &kss->ks8851; ks->lock = ks8851_lock_spi; ks->unlock = ks8851_unlock_spi; @@ -435,8 +436,6 @@ static int ks8851_probe_spi(struct spi_device *spi) IRQ_RXPSI) /* RX process stop */ ks->rc_ier = STD_IRQ; - kss = to_ks8851_spi(ks); - kss->spidev = spi; mutex_init(&kss->lock); INIT_WORK(&kss->tx_work, ks8851_tx_work); -- 2.35.1