Source-Changes-HG archive

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

[src/trunk]: src/sys/net in ifmedia_add(), use a wait-style memory allocation...



details:   https://anonhg.NetBSD.org/src/rev/5d9335046be0
branches:  trunk
changeset: 965776:5d9335046be0
user:      chs <chs%NetBSD.org@localhost>
date:      Tue Oct 01 17:45:25 2019 +0000

description:
in ifmedia_add(), use a wait-style memory allocation rather than
not waiting and panic'ing if the allocation fails.

Reported-by: syzbot+249ca42197f0b066e154%syzkaller.appspotmail.com@localhost

diffstat:

 sys/net/if_media.c |  12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diffs (43 lines):

diff -r 28ec66e253f7 -r 5d9335046be0 sys/net/if_media.c
--- a/sys/net/if_media.c        Tue Oct 01 17:40:22 2019 +0000
+++ b/sys/net/if_media.c        Tue Oct 01 17:45:25 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $        */
+/*     $NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -162,14 +162,10 @@
        }
 #endif
 
-       entry = malloc(sizeof(*entry), M_IFMEDIA, M_NOWAIT);
-       if (entry == NULL)
-               panic("ifmedia_add: can't malloc entry");
-
+       entry = malloc(sizeof(*entry), M_IFMEDIA, M_WAITOK);
        entry->ifm_media = mword;
        entry->ifm_data = data;
        entry->ifm_aux = aux;
-
        TAILQ_INSERT_TAIL(&ifm->ifm_list, entry, ifm_list);
 }
 
@@ -335,8 +331,6 @@
                        int *kptr = malloc(minwords * sizeof(int), M_TEMP,
                            M_WAITOK);
 
-                       if (kptr == NULL)
-                               return ENOMEM;
                        /* Get the media words from the interface's list. */
                        ep = TAILQ_FIRST(&ifm->ifm_list);
                        for (count = 0; ep != NULL && count < minwords;



Home | Main Index | Thread Index | Old Index