Skip to content

Commit de84da5

Browse files
visitorckwdlezcano
authored andcommitted
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 <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ebd1dea commit de84da5

File tree

1 file changed

+0
-16
lines changed

1 file changed

+0
-16
lines changed

tools/thermal/lib/mainloop.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "log.h"
1010

1111
static int epfd = -1;
12-
static unsigned short nrhandler;
1312
static sig_atomic_t exit_mainloop;
1413

1514
struct mainloop_data {
@@ -18,8 +17,6 @@ struct mainloop_data {
1817
int fd;
1918
};
2019

21-
static struct mainloop_data **mds;
22-
2320
#define MAX_EVENTS 10
2421

2522
int mainloop(unsigned int timeout)
@@ -61,13 +58,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data)
6158

6259
struct mainloop_data *md;
6360

64-
if (fd >= nrhandler) {
65-
mds = realloc(mds, sizeof(*mds) * (fd + 1));
66-
if (!mds)
67-
return -1;
68-
nrhandler = fd + 1;
69-
}
70-
7161
md = malloc(sizeof(*md));
7262
if (!md)
7363
return -1;
@@ -76,7 +66,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data)
7666
md->cb = cb;
7767
md->fd = fd;
7868

79-
mds[fd] = md;
8069
ev.data.ptr = md;
8170

8271
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) < 0) {
@@ -89,14 +78,9 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data)
8978

9079
int mainloop_del(int fd)
9180
{
92-
if (fd >= nrhandler)
93-
return -1;
94-
9581
if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL) < 0)
9682
return -1;
9783

98-
free(mds[fd]);
99-
10084
return 0;
10185
}
10286

0 commit comments

Comments
 (0)