From nobody Wed Apr 8 07:48:41 2026 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 0F9DDC32792 for ; Mon, 22 Aug 2022 21:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238182AbiHVVjl (ORCPT ); Mon, 22 Aug 2022 17:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237803AbiHVVji (ORCPT ); Mon, 22 Aug 2022 17:39:38 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C074652097; Mon, 22 Aug 2022 14:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1661204375; x=1692740375; h=from:to:subject:date:message-id:mime-version; bh=ZrNeU8CEeIl3AZc1VJMb4npC0a4B7n74iwOT/dV4tiA=; b=1UIoy1rZmEVyUGihuaoN4hIXY7FbrfX7sHcJfiQLhtl3XZQ0R39tL+S8 8bvZ16uECMXjJmeekQVB5yWQduUsuhAU5q8kqiDB6RsHHD5rfgS+c7cmb J45awJC3G2KhcTs00TJFjXpTDs2txbqUszplMQ8tn7tWz+G5XOZXVjuur 0ty5Zp8nsdt81ueTfXLGeqcQnNwluVaZJbQr0euN/qHHIFUZmbfqPakec rNYpJRUOHF5G0/0ALw3usVA46DKJUP80UNbN/Re4fN7laWx8ThMZMo9Yd Nrp+xzVfj4NmhAywzS4YGtSGnSSPEk+GiANFMrQ7wYTRH7pJv9WsltA6K Q==; X-IronPort-AV: E=Sophos;i="5.93,255,1654585200"; d="scan'208";a="187595698" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 22 Aug 2022 14:39:35 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 22 Aug 2022 14:39:34 -0700 Received: from AUS-LT-C33025.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 22 Aug 2022 14:39:33 -0700 From: Jerry Ray To: "David S . Miller " , Jakub Kicinski , Jerry Ray , , , Subject: [PATCH] micrel: ksz8851: fixes struct pointer issue Date: Mon, 22 Aug 2022 16:39:32 -0500 Message-ID: <20220822213932.12848-1-jerry.ray@microchip.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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/etherne= t/micrel/ks8851_spi.c index 479406ecbaa3..13c76352ae8d 100644 --- a/drivers/net/ethernet/micrel/ks8851_spi.c +++ b/drivers/net/ethernet/micrel/ks8851_spi.c @@ -413,7 +413,8 @@ static int ks8851_probe_spi(struct spi_device *spi) =20 spi->bits_per_word =3D 8; =20 - ks =3D netdev_priv(netdev); + kss =3D netdev_priv(netdev); + ks =3D &kss->ks8851; =20 ks->lock =3D ks8851_lock_spi; ks->unlock =3D ks8851_unlock_spi; @@ -433,8 +434,6 @@ static int ks8851_probe_spi(struct spi_device *spi) IRQ_RXPSI) /* RX process stop */ ks->rc_ier =3D STD_IRQ; =20 - kss =3D to_ks8851_spi(ks); - kss->spidev =3D spi; mutex_init(&kss->lock); INIT_WORK(&kss->tx_work, ks8851_tx_work); --=20 2.17.1