From d43d78e59ca379ad180dea81295036b3b13f6453 Mon Sep 17 00:00:00 2001 From: Metin Kaya Date: Wed, 11 Sep 2024 11:29:50 +0100 Subject: [PATCH 1/2] lisa._assets.kmodules.lisa: Check return value of kernel_write() FIX Better to check return value of kernel_write() since it may fail and help in debugging exceptions in 'pixel6.c'. While we are here, fix some trivial whitespacing issues. Signed-off-by: Metin Kaya --- lisa/_assets/kmodules/lisa/pixel6.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lisa/_assets/kmodules/lisa/pixel6.c b/lisa/_assets/kmodules/lisa/pixel6.c index f7f898ed6..447603f74 100644 --- a/lisa/_assets/kmodules/lisa/pixel6.c +++ b/lisa/_assets/kmodules/lisa/pixel6.c @@ -41,7 +41,7 @@ typedef struct emeter_buffer_private { static struct file *open_file(int *error, const char *path, umode_t mode) { - struct file* file; + struct file *file; file = filp_open(path, mode, 0); if (IS_ERR_OR_NULL(file)) { pr_err("Could not open %s: %li\n", path, file ? PTR_ERR(file) : 0); @@ -62,10 +62,16 @@ static void close_file(int *error, struct file *file) } } -static void write_str(struct file *file, char *str) +static void write_str(int *error, struct file *file, char *str) { - if (file) { - kernel_write(file, str, strlen(str) + 1, 0); + ssize_t ret = -ENOENT; + + if (file) + ret = kernel_write(file, str, strlen(str) + 1, 0); + + if (ret < 0) { + pr_err("Could not write string: %zi\n", ret); + *error |= 1; } } @@ -133,9 +139,9 @@ static int p6_emeter_worker(void *data) { } -static int enable_p6_emeter(struct feature* feature) { +static int enable_p6_emeter(struct feature *feature) { struct p6_emeter_data *data = NULL; - struct file* sample_file = NULL; + struct file *sample_file = NULL; struct file *rate_file = NULL; int ret = 0; @@ -152,12 +158,12 @@ static int enable_p6_emeter(struct feature* feature) { *an updated value every 8 hardware periods */ rate_file = open_file(&ret, POWER_METER_RATE_FILE_0, O_WRONLY); - write_str(rate_file, "500\n"); + write_str(&ret, rate_file, "500\n"); close_file(&ret, rate_file); HANDLE_ERR(ret); rate_file = open_file(&ret, POWER_METER_RATE_FILE_1, O_WRONLY); - write_str(rate_file, "500\n"); + write_str(&ret, rate_file, "500\n"); close_file(&ret, rate_file); HANDLE_ERR(ret); -- GitLab From 05f493212d901166a24a9c79d55e5e5ccb8a326c Mon Sep 17 00:00:00 2001 From: Metin Kaya Date: Wed, 11 Sep 2024 11:34:35 +0100 Subject: [PATCH 2/2] lisa/_assets/kmodules/lisa: Fix typo __worqueue FIX It should be __workqueue instead. Signed-off-by: Metin Kaya --- lisa/_assets/kmodules/lisa/pixel6.c | 4 ++-- lisa/_assets/kmodules/lisa/wq.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lisa/_assets/kmodules/lisa/pixel6.c b/lisa/_assets/kmodules/lisa/pixel6.c index 447603f74..00db38648 100644 --- a/lisa/_assets/kmodules/lisa/pixel6.c +++ b/lisa/_assets/kmodules/lisa/pixel6.c @@ -147,7 +147,7 @@ static int enable_p6_emeter(struct feature *feature) { #define HANDLE_ERR(code) if (code) {ret |= code; goto finish;} - HANDLE_ERR(ENABLE_FEATURE(__worqueue)) + HANDLE_ERR(ENABLE_FEATURE(__workqueue)) data = kzalloc(sizeof(*data), GFP_KERNEL); feature->data = data; @@ -190,7 +190,7 @@ static int disable_p6_emeter(struct feature* feature) { if (data) free_p6_emeter_data(data); - ret |= DISABLE_FEATURE(__worqueue); + ret |= DISABLE_FEATURE(__workqueue); return ret; }; diff --git a/lisa/_assets/kmodules/lisa/wq.c b/lisa/_assets/kmodules/lisa/wq.c index e9cbb5484..be641ffef 100644 --- a/lisa/_assets/kmodules/lisa/wq.c +++ b/lisa/_assets/kmodules/lisa/wq.c @@ -24,7 +24,7 @@ static void worker(struct work_struct* work) { struct work_item *start_work(worker_t f, int delay, void *data) { struct work_item *item; - struct workqueue_struct *wq = FEATURE(__worqueue)->data; + struct workqueue_struct *wq = FEATURE(__workqueue)->data; if (!wq) return NULL; @@ -68,7 +68,7 @@ static int deinit_wq(struct feature *feature) { destroy_workqueue(wq); return 0; } -DEFINE_INTERNAL_FEATURE(__worqueue, init_wq, deinit_wq); +DEFINE_INTERNAL_FEATURE(__workqueue, init_wq, deinit_wq); /* @@ -97,7 +97,7 @@ __maybe_unused static int example_init(struct feature *feature) { struct example_data *data; pr_info("Starting worker for feature %s\n", feature->name); - if (ENABLE_FEATURE(__worqueue)) + if (ENABLE_FEATURE(__workqueue)) return 1; data = kmalloc(sizeof(*data), GFP_KERNEL); @@ -123,7 +123,7 @@ __maybe_unused static int example_deinit(struct feature *feature) { kfree(data); } - ret |= DISABLE_FEATURE(__worqueue); + ret |= DISABLE_FEATURE(__workqueue); return ret; } -- GitLab