diff mbox series

[net-next,v1,2/3] net: dsa: ksz: ksz8795_spi_probe: fix possible NULL pointer dereference

Message ID 20210429110833.2181-2-o.rempel@pengutronix.de (mailing list archive)
State Accepted
Commit ba46b576a7954fa54ff4c1ef976624794b6668f6
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1,1/3] net: dsa: ksz: ksz8863_smi_probe: fix possible NULL pointer dereference | expand

Checks

Context Check Description
netdev/cover_letter warning Series does not have a cover letter
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers fail 1 blamed authors not CCed: linux@rempel-privat.de; 1 maintainers not CCed: linux@rempel-privat.de
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Oleksij Rempel April 29, 2021, 11:08 a.m. UTC
Fix possible NULL pointer dereference in case devm_kzalloc() failed to
allocate memory

Fixes: cc13e52c3a89 ("net: dsa: microchip: Add Microchip KSZ8863 SPI based driver support")
Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8795_spi.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andrew Lunn April 29, 2021, 12:14 p.m. UTC | #1
On Thu, Apr 29, 2021 at 01:08:32PM +0200, Oleksij Rempel wrote:
> Fix possible NULL pointer dereference in case devm_kzalloc() failed to
> allocate memory
> 
> Fixes: cc13e52c3a89 ("net: dsa: microchip: Add Microchip KSZ8863 SPI based driver support")
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz8795_spi.c
index 85ba12aa82d8..ea7550d1b634 100644
--- a/drivers/net/dsa/microchip/ksz8795_spi.c
+++ b/drivers/net/dsa/microchip/ksz8795_spi.c
@@ -41,6 +41,9 @@  static int ksz8795_spi_probe(struct spi_device *spi)
 	int i, ret = 0;
 
 	ksz8 = devm_kzalloc(&spi->dev, sizeof(struct ksz8), GFP_KERNEL);
+	if (!ksz8)
+		return -ENOMEM;
+
 	ksz8->priv = spi;
 
 	dev = ksz_switch_alloc(&spi->dev, ksz8);