Skip to content

Commit

Permalink
micrel: ksz8851: fixes struct pointer issue
Browse files Browse the repository at this point in the history
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 <jerry.ray@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jerry Ray authored and David S. Miller committed Aug 24, 2022
1 parent aacd467 commit fef5de7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/net/ethernet/micrel/ks8851_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,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;
Expand All @@ -433,8 +434,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);
Expand Down

0 comments on commit fef5de7

Please sign in to comment.