From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: daniel.lezcano@linaro.org, rafael@kernel.org
Cc: amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Kuan-Wei Chiu <visitorckw@gmail.com>
Subject: [PATCH v2] tools/thermal: remove unused 'mds' and 'nrhandler' variables
Date: Wed, 27 Sep 2023 01:37:36 +0800 [thread overview]
Message-ID: <20230926173736.1142420-1-visitorckw@gmail.com> (raw)
In-Reply-To: <93c87b5c-ae8f-d27d-0342-faa884a3142e@linaro.org>
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>
---
Changes since v1:
* Remove the unused 'mds' and 'nrhandler' variables along with the
associated code.
tools/thermal/lib/mainloop.c | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/tools/thermal/lib/mainloop.c b/tools/thermal/lib/mainloop.c
index 94cbbcbd1c14..bf4c1b730d7b 100644
--- a/tools/thermal/lib/mainloop.c
+++ b/tools/thermal/lib/mainloop.c
@@ -9,7 +9,6 @@
#include "log.h"
static int epfd = -1;
-static unsigned short nrhandler;
static sig_atomic_t exit_mainloop;
struct mainloop_data {
@@ -18,8 +17,6 @@ struct mainloop_data {
int fd;
};
-static struct mainloop_data **mds;
-
#define MAX_EVENTS 10
int mainloop(unsigned int timeout)
@@ -61,13 +58,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data)
struct mainloop_data *md;
- if (fd >= nrhandler) {
- mds = realloc(mds, sizeof(*mds) * (fd + 1));
- if (!mds)
- return -1;
- nrhandler = fd + 1;
- }
-
md = malloc(sizeof(*md));
if (!md)
return -1;
@@ -76,7 +66,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data)
md->cb = cb;
md->fd = fd;
- mds[fd] = md;
ev.data.ptr = md;
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)
int mainloop_del(int fd)
{
- if (fd >= nrhandler)
- return -1;
-
if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL) < 0)
return -1;
- free(mds[fd]);
-
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2023-09-26 17:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-24 6:50 [PATCH] tools/thermal: fix memory leak in realloc failure handling Kuan-Wei Chiu
2023-09-25 9:42 ` Daniel Lezcano
2023-09-26 17:37 ` Kuan-Wei Chiu [this message]
2023-09-28 13:48 ` [PATCH v2] tools/thermal: remove unused 'mds' and 'nrhandler' variables Daniel Lezcano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230926173736.1142420-1-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®