From: <shiju.jose@huawei.com>
To: <mchehab@kernel.org>, <linux-edac@vger.kernel.org>
Cc: <jonathan.cameron@huawei.com>, <linuxarm@huawei.com>,
<tanxiaofei@huawei.com>, <lvying6@huawei.com>,
<fenglei47@h-partners.com>, <shiju.jose@huawei.com>
Subject: [RFC PATCH V2 1/3] rasdaemon: fix return value type issue of read/write function from unistd.h
Date: Thu, 1 Jun 2023 00:06:24 +0800 [thread overview]
Message-ID: <20230531160627.1506-2-shiju.jose@huawei.com> (raw)
In-Reply-To: <20230531160627.1506-1-shiju.jose@huawei.com>
From: Xiaofei Tan <tanxiaofei@huawei.com>
The return value type of read/write function from unistd.h is ssize_t.
It's signed normally, and return -1 on error. Fix incorrect use in the
function read_ras_event_all_cpus().
BTW, make setting buffer_percent as a separate function.
Fixes: 94750bcf9309 ("rasdaemon: Fix poll() on per_cpu trace_pipe_raw blocks indefinitely")
Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
---
ras-events.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/ras-events.c b/ras-events.c
index 2662467..d041828 100644
--- a/ras-events.c
+++ b/ras-events.c
@@ -368,10 +368,37 @@ static int get_num_cpus(struct ras_events *ras)
#endif
}
+static int set_buffer_percent(struct ras_events *ras, int percent)
+{
+ char buf[16];
+ ssize_t size;
+ int res = 0;
+ int fd;
+
+ fd = open_trace(ras, "buffer_percent", O_WRONLY);
+ if (fd >= 0) {
+ /* For the backward compatibility to the old kernels, do not return
+ * if fail to set the buffer_percent.
+ */
+ snprintf(buf, sizeof(buf), "%d", percent);
+ size = write(fd, buf, strlen(buf));
+ if (size <= 0) {
+ log(TERM, LOG_WARNING, "can't write to buffer_percent\n");
+ res = -1;
+ }
+ close(fd);
+ } else {
+ log(TERM, LOG_WARNING, "Can't open buffer_percent\n");
+ res = -1;
+ }
+
+ return res;
+}
+
static int read_ras_event_all_cpus(struct pthread_data *pdata,
unsigned n_cpus)
{
- unsigned size;
+ ssize_t size;
unsigned long long time_stamp;
void *data;
int ready, i, count_nready;
@@ -383,8 +410,6 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
int warnonce[n_cpus];
char pipe_raw[PATH_MAX];
int legacy_kernel = 0;
- int fd;
- char buf[16];
#if 0
int need_sleep = 0;
#endif
@@ -411,18 +436,8 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
* Set buffer_percent to 0 so that poll() will return immediately
* when the trace data is available in the ras per_cpu trace pipe_raw
*/
- fd = open_trace(pdata[0].ras, "buffer_percent", O_WRONLY);
- if (fd >= 0) {
- /* For the backward compatibility to the old kernels, do not return
- * if fail to set the buffer_percent.
- */
- snprintf(buf, sizeof(buf), "0");
- size = write(fd, buf, strlen(buf));
- if (size <= 0)
- log(TERM, LOG_WARNING, "can't write to buffer_percent\n");
- close(fd);
- } else
- log(TERM, LOG_WARNING, "Can't open buffer_percent\n");
+ if (set_buffer_percent(pdata[0].ras, 0))
+ log(TERM, LOG_WARNING, "Set buffer_percent failed\n");
for (i = 0; i < (n_cpus + 1); i++)
fds[i].fd = -1;
--
2.25.1
next prev parent reply other threads:[~2023-05-31 16:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 16:06 [RFC PATCH V2 0/3] rasdaemon: Fix return value type issue, some clean-ups and add support for creating vendor tables at startup shiju.jose
2023-05-31 16:06 ` shiju.jose [this message]
2023-05-31 16:06 ` [RFC PATCH V2 2/3] rasdaemon: fix issue of signed and unsigned integer comparison and remove redundant header file shiju.jose
2023-05-31 16:06 ` [RFC PATCH V2 3/3] rasdaemon: Add support for creating the vendor error tables at startup shiju.jose
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=20230531160627.1506-2-shiju.jose@huawei.com \
--to=shiju.jose@huawei.com \
--cc=fenglei47@h-partners.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-edac@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=lvying6@huawei.com \
--cc=mchehab@kernel.org \
--cc=tanxiaofei@huawei.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;
as well as URLs for NNTP newsgroup(s).