Skip to content

Commit be30913

Browse files
committed
getevent: fix warnings and minor improvements
1 fix warning assignment discards 'volatile' qualifier from pointer target type 2 add errno logging 3 malloc change to calloc VELAPLATFO-85827 Change-Id: Ia265e2c9bbdff9ce6b1d53de705611eaf412e1d1 Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
1 parent f363d51 commit be30913

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

graphics/input/getevent/getevent.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int open_device(FAR struct input_device_s *dev)
101101

102102
if (dev->fd < 0)
103103
{
104-
GETEVENT_INFO("open %s failed:%d\n", dev->path, errno);
104+
GETEVENT_INFO("open %s failed, errno: %d\n", dev->path, errno);
105105
return -errno;
106106
}
107107

@@ -126,11 +126,12 @@ static int touch_init(FAR struct input_device_s *dev)
126126
ret = ioctl(dev->fd, TSIOC_GETMAXPOINTS, &maxpoint);
127127
if (ret < 0)
128128
{
129-
GETEVENT_INFO("ioctl GETMAXPOINTS failed: %d\n", ret);
129+
GETEVENT_INFO("ioctl GETMAXPOINTS failed: %d, "
130+
"errno: %d\n", ret, errno);
130131
return -errno;
131132
}
132133

133-
priv = malloc(sizeof(struct touch_priv_s) +
134+
priv = calloc(1, sizeof(struct touch_priv_s) +
134135
SIZEOF_TOUCH_SAMPLE_S(maxpoint));
135136
if (!priv)
136137
{
@@ -292,7 +293,7 @@ static void run_event_loop(FAR struct input_devices_ctx_s *ctx)
292293
sa.sa_flags = SA_SIGINFO;
293294
sa.sa_sigaction = signal_handler;
294295
sigemptyset(&sa.sa_mask);
295-
sa.sa_user = &running;
296+
sa.sa_user = (FAR void *)&running;
296297
sigaction(SIGINT, &sa, NULL);
297298

298299
for (dev = ctx->head; dev; dev = dev->next)
@@ -303,7 +304,13 @@ static void run_event_loop(FAR struct input_devices_ctx_s *ctx)
303304
}
304305
}
305306

306-
fds = malloc(fd_count * sizeof(struct pollfd));
307+
fds = calloc(fd_count, sizeof(struct pollfd));
308+
309+
if (!fds)
310+
{
311+
GETEVENT_INFO("Memory allocation failed for fds\n");
312+
return;
313+
}
307314

308315
for (dev = ctx->head; dev; dev = dev->next)
309316
{
@@ -327,15 +334,17 @@ static void run_event_loop(FAR struct input_devices_ctx_s *ctx)
327334

328335
for (i = 0; i < fd_count; i++)
329336
{
330-
if (fds[i].revents & POLLIN)
337+
if (!(fds[i].revents & POLLIN))
338+
{
339+
continue;
340+
}
341+
342+
for (dev = ctx->head; dev; dev = dev->next)
331343
{
332-
for (dev = ctx->head; dev; dev = dev->next)
344+
if (dev->fd == fds[i].fd)
333345
{
334-
if (dev->fd == fds[i].fd)
335-
{
336-
dev->read_cb(dev);
337-
break;
338-
}
346+
dev->read_cb(dev);
347+
break;
339348
}
340349
}
341350
}
@@ -371,14 +380,13 @@ alloc_input_device(FAR struct input_devices_ctx_s *ctx,
371380
FAR struct input_device_s *cur;
372381
size_t path_len = strlen(path) + 1;
373382

374-
dev = malloc(sizeof(struct input_device_s) + path_len);
383+
dev = calloc(1, sizeof(struct input_device_s) + path_len);
375384
if (!dev)
376385
{
377386
GETEVENT_INFO("Memory allocation failed for device\n");
378387
return NULL;
379388
}
380389

381-
memset(dev, 0, sizeof(struct input_device_s));
382390
memcpy(dev->path, path, path_len);
383391

384392
if (!ctx->head)
@@ -436,7 +444,7 @@ static int detect_devices(FAR struct input_devices_ctx_s *ctx)
436444
dir = opendir("/dev");
437445
if (!dir)
438446
{
439-
GETEVENT_INFO("Failed to open /dev directory\n");
447+
GETEVENT_INFO("Failed to open /dev directory, errno: %d\n", errno);
440448
return -errno;
441449
}
442450

0 commit comments

Comments
 (0)