Skip to content

Commit add7c5e

Browse files
committed
wpad: use malloc instead of lwp_wkspace alloc, check for OOM error
1 parent df5c999 commit add7c5e

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

wiiuse/io_wii.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,18 @@ void wiiuse_sensorbar_enable(int enable)
265265
__wiiuse_sensorbar_enable(enable);
266266
}
267267

268-
void wiiuse_init_cmd_queue(struct wiimote_t *wm)
268+
int wiiuse_init_cmd_queue(struct wiimote_t *wm)
269269
{
270270
u32 size;
271271

272272
if (!__queue_buffer[wm->unid]) {
273273
size = (MAX_COMMANDS*sizeof(struct cmd_blk_t));
274-
__queue_buffer[wm->unid] = __lwp_wkspace_allocate(size);
275-
if(!__queue_buffer[wm->unid]) return;
274+
__queue_buffer[wm->unid] = malloc(size);
275+
if(!__queue_buffer[wm->unid]) return ERR_MEM;
276276
}
277277

278278
__lwp_queue_initialize(&wm->cmdq,__queue_buffer[wm->unid],MAX_COMMANDS,sizeof(struct cmd_blk_t));
279+
return ERR_OK;
279280
}
280281

281282
int wiiuse_io_write(struct wiimote_t *wm,ubyte *buf,int len)

wiiuse/wiiuse.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb) {
6666
return NULL;
6767

6868
if (!__wm) {
69-
__wm = __lwp_wkspace_allocate(sizeof(struct wiimote_t*) * wiimotes);
69+
__wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
7070
if(!__wm) return NULL;
7171
memset(__wm, 0, sizeof(struct wiimote_t*) * wiimotes);
7272
}
7373

7474
for (i = 0; i < wiimotes; ++i) {
7575
if(!__wm[i])
76-
__wm[i] = __lwp_wkspace_allocate(sizeof(struct wiimote_t));
76+
__wm[i] = malloc(sizeof(struct wiimote_t));
7777

7878
memset(__wm[i], 0, sizeof(struct wiimote_t));
7979
__wm[i]->unid = i;
@@ -88,7 +88,10 @@ struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb) {
8888
__wm[i]->sock = NULL;
8989
__wm[i]->bdaddr = *BD_ADDR_ANY;
9090
__wm[i]->event_cb = event_cb;
91-
wiiuse_init_cmd_queue(__wm[i]);
91+
if (wiiuse_init_cmd_queue(__wm[i])) {
92+
WIIUSE_ERROR("Could not allocate command queue");
93+
return NULL;
94+
}
9295
#elif defined(unix)
9396
__wm[i]->bdaddr = *BDADDR_ANY;
9497
__wm[i]->out_sock = -1;

wiiuse/wiiuse_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct op_t
267267
} __attribute__((packed));
268268

269269
/* not part of the api */
270-
void wiiuse_init_cmd_queue(struct wiimote_t *wm);
270+
int wiiuse_init_cmd_queue(struct wiimote_t *wm);
271271
void wiiuse_send_next_command(struct wiimote_t *wm);
272272
int wiiuse_set_report_type(struct wiimote_t* wm,cmd_blk_cb cb);
273273
int wiiuse_sendcmd(struct wiimote_t *wm,ubyte report_type,ubyte *msg,int len,cmd_blk_cb cb);

0 commit comments

Comments
 (0)