Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for...



details:   https://anonhg.NetBSD.org/src/rev/4e025c699b6b
branches:  trunk
changeset: 359623:4e025c699b6b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jan 14 22:26:45 2022 +0000

description:
ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for failure.

diffstat:

 sys/dev/i2c/ihidev.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (43 lines):

diff -r d1e4fd728e45 -r 4e025c699b6b sys/dev/i2c/ihidev.c
--- a/sys/dev/i2c/ihidev.c      Fri Jan 14 22:26:35 2022 +0000
+++ b/sys/dev/i2c/ihidev.c      Fri Jan 14 22:26:45 2022 +0000
@@ -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 @@
                 */
                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 @@
                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);



Home | Main Index | Thread Index | Old Index