Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/thermal: Remove unused 'mds' and 'nrhandler' variables

In the previous code, the 'mds' and 'nrhandler' variables were not
utilized in the codebase. Additionally, there was a potential NULL
pointer dereference and memory leak due to improper handling of memory
reallocation failure.

This patch removes the unused 'mds' and 'nrhandler' variables along with
the associated code, addressing the unused variable issue, NULL pointer
dereference issue and the memory leak issue.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230926173736.1142420-1-visitorckw@gmail.com

authored by

Kuan-Wei Chiu and committed by
Daniel Lezcano
de84da58 ebd1dea9

-16
-16
tools/thermal/lib/mainloop.c
··· 9 9 #include "log.h" 10 10 11 11 static int epfd = -1; 12 - static unsigned short nrhandler; 13 12 static sig_atomic_t exit_mainloop; 14 13 15 14 struct mainloop_data { ··· 16 17 void *data; 17 18 int fd; 18 19 }; 19 - 20 - static struct mainloop_data **mds; 21 20 22 21 #define MAX_EVENTS 10 23 22 ··· 58 61 59 62 struct mainloop_data *md; 60 63 61 - if (fd >= nrhandler) { 62 - mds = realloc(mds, sizeof(*mds) * (fd + 1)); 63 - if (!mds) 64 - return -1; 65 - nrhandler = fd + 1; 66 - } 67 - 68 64 md = malloc(sizeof(*md)); 69 65 if (!md) 70 66 return -1; ··· 66 76 md->cb = cb; 67 77 md->fd = fd; 68 78 69 - mds[fd] = md; 70 79 ev.data.ptr = md; 71 80 72 81 if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) < 0) { ··· 78 89 79 90 int mainloop_del(int fd) 80 91 { 81 - if (fd >= nrhandler) 82 - return -1; 83 - 84 92 if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL) < 0) 85 93 return -1; 86 - 87 - free(mds[fd]); 88 94 89 95 return 0; 90 96 }