Skip to content

Commit fef5de7

Browse files
Jerry0443davem330
authored andcommitted
micrel: ksz8851: fixes struct pointer issue
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aacd467 commit fef5de7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/net/ethernet/micrel/ks8851_spi.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ static int ks8851_probe_spi(struct spi_device *spi)
413413

414414
spi->bits_per_word = 8;
415415

416-
ks = netdev_priv(netdev);
416+
kss = netdev_priv(netdev);
417+
ks = &kss->ks8851;
417418

418419
ks->lock = ks8851_lock_spi;
419420
ks->unlock = ks8851_unlock_spi;
@@ -433,8 +434,6 @@ static int ks8851_probe_spi(struct spi_device *spi)
433434
IRQ_RXPSI) /* RX process stop */
434435
ks->rc_ier = STD_IRQ;
435436

436-
kss = to_ks8851_spi(ks);
437-
438437
kss->spidev = spi;
439438
mutex_init(&kss->lock);
440439
INIT_WORK(&kss->tx_work, ks8851_tx_work);

0 commit comments

Comments
 (0)