Module Name: src Committed By: riastradh Date: Fri Jan 14 22:26:45 UTC 2022
Modified Files: src/sys/dev/i2c: ihidev.c Log Message: ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for failure. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/dev/i2c/ihidev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/i2c/ihidev.c diff -u src/sys/dev/i2c/ihidev.c:1.22 src/sys/dev/i2c/ihidev.c:1.23 --- src/sys/dev/i2c/ihidev.c:1.22 Fri Jan 14 22:26:35 2022 +++ src/sys/dev/i2c/ihidev.c Fri Jan 14 22:26:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ihidev.c,v 1.22 2022/01/14 22:26:35 riastradh Exp $ */ +/* $NetBSD: ihidev.c,v 1.23 2022/01/14 22:26:45 riastradh Exp $ */ /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */ /*- @@ -54,7 +54,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.22 2022/01/14 22:26:35 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.23 2022/01/14 22:26:45 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -416,6 +416,13 @@ ihidev_hid_command(struct ihidev_softc * */ report_len += report_id_len; tmprep = kmem_zalloc(report_len, KM_NOSLEEP); + if (tmprep == NULL) { + /* XXX pool or preallocate? */ + DPRINTF(("%s: out of memory\n", + device_xname(sc->sc_dev))); + res = ENOMEM; + break; + } /* type 3 id 8: 22 00 38 02 23 00 */ res = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, @@ -507,6 +514,10 @@ ihidev_hid_command(struct ihidev_softc * cmd[dataoff] = rreq->id; finalcmd = kmem_zalloc(cmdlen + rreq->len, KM_NOSLEEP); + if (finalcmd == NULL) { + res = ENOMEM; + break; + } memcpy(finalcmd, cmd, cmdlen); memcpy(finalcmd + cmdlen, rreq->data, rreq->len);