Tue May 31 15:24:59 2022 UTC ()
Restore NULL pointer checks lost in rev 1.16.

Fixes PR port-atari/56859, ok'ed mlelstv@, and confirmed on TT030.
Should be pulled up to netbsd-9 and netbsd-8.


(tsutsui)
diff -r1.16 -r1.17 src/sys/arch/atari/atari/stalloc.c

cvs diff -r1.16 -r1.17 src/sys/arch/atari/atari/stalloc.c (expand / switch to unified diff)

--- src/sys/arch/atari/atari/stalloc.c 2014/01/03 07:14:20 1.16
+++ src/sys/arch/atari/atari/stalloc.c 2022/05/31 15:24:59 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: stalloc.c,v 1.16 2014/01/03 07:14:20 mlelstv Exp $ */ 1/* $NetBSD: stalloc.c,v 1.17 2022/05/31 15:24:59 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1995 Leo Weppelman (Atari modifications) 4 * Copyright (c) 1995 Leo Weppelman (Atari modifications)
5 * Copyright (c) 1994 Christian E. Hopps (allocator stuff) 5 * Copyright (c) 1994 Christian E. Hopps (allocator stuff)
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE. 33 * SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: stalloc.c,v 1.16 2014/01/03 07:14:20 mlelstv Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: stalloc.c,v 1.17 2022/05/31 15:24:59 tsutsui Exp $");
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/queue.h> 42#include <sys/queue.h>
43 43
44#include <atari/atari/stalloc.h> 44#include <atari/atari/stalloc.h>
45 45
46/* 46/*
47 * St-mem allocator. 47 * St-mem allocator.
48 */ 48 */
49/* 49/*
50 * From atari_init.c 50 * From atari_init.c
@@ -153,38 +153,38 @@ free_stmem(void *mem) @@ -153,38 +153,38 @@ free_stmem(void *mem)
153 int s; 153 int s;
154 154
155 if (mem == NULL) 155 if (mem == NULL)
156 return; 156 return;
157 157
158 s = splhigh(); 158 s = splhigh();
159 mn = (struct mem_node *)mem - 1; 159 mn = (struct mem_node *)mem - 1;
160 next = TAILQ_NEXT(mn, link); 160 next = TAILQ_NEXT(mn, link);
161 prev = TAILQ_PREV(mn, stlist, link); 161 prev = TAILQ_PREV(mn, stlist, link);
162 162
163 /* 163 /*
164 * check ahead of us. 164 * check ahead of us.
165 */ 165 */
166 if (next->type == MNODE_FREE) { 166 if (next != NULL && next->type == MNODE_FREE) {
167 /* 167 /*
168 * if next is: a valid node and a free node. ==> merge 168 * if next is: a valid node and a free node. ==> merge
169 */ 169 */
170 TAILQ_INSERT_BEFORE(next, mn, free_link); 170 TAILQ_INSERT_BEFORE(next, mn, free_link);
171 mn->type = MNODE_FREE; 171 mn->type = MNODE_FREE;
172 TAILQ_REMOVE(&st_list, next, link); 172 TAILQ_REMOVE(&st_list, next, link);
173 TAILQ_REMOVE(&free_list, next, free_link); 173 TAILQ_REMOVE(&free_list, next, free_link);
174 stmem_total += mn->size + sizeof(struct mem_node); 174 stmem_total += mn->size + sizeof(struct mem_node);
175 mn->size += next->size + sizeof(struct mem_node); 175 mn->size += next->size + sizeof(struct mem_node);
176 } 176 }
177 if (prev->type == MNODE_FREE) { 177 if (prev != NULL && prev->type == MNODE_FREE) {
178 /* 178 /*
179 * if prev is: a valid node and a free node. ==> merge 179 * if prev is: a valid node and a free node. ==> merge
180 */ 180 */
181 if (mn->type != MNODE_FREE) 181 if (mn->type != MNODE_FREE)
182 stmem_total += mn->size + sizeof(struct mem_node); 182 stmem_total += mn->size + sizeof(struct mem_node);
183 else { 183 else {
184 /* already on free list */ 184 /* already on free list */
185 TAILQ_REMOVE(&free_list, mn, free_link); 185 TAILQ_REMOVE(&free_list, mn, free_link);
186 mn->type = MNODE_USED; 186 mn->type = MNODE_USED;
187 stmem_total += sizeof(struct mem_node); 187 stmem_total += sizeof(struct mem_node);
188 } 188 }
189 TAILQ_REMOVE(&st_list, mn, link); 189 TAILQ_REMOVE(&st_list, mn, link);
190 prev->size += mn->size + sizeof(struct mem_node); 190 prev->size += mn->size + sizeof(struct mem_node);