public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] kunit: debugfs: Fix unchecked dereference in debugfs_print_results()
@ 2023-10-30 10:47 Richard Fitzgerald
  2023-11-30 20:57 ` Rae Moar
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Fitzgerald @ 2023-10-30 10:47 UTC (permalink / raw)
  To: brendan.higgins, davidgow, rmoar
  Cc: linux-kselftest, kunit-dev, linux-kernel, patches,
	Richard Fitzgerald, Dan Carpenter

Move the call to kunit_suite_has_succeeded() after the check that
the kunit_suite pointer is valid.

This was found by smatch:

 lib/kunit/debugfs.c:66 debugfs_print_results() warn: variable
 dereferenced before check 'suite' (see line 63)

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: 38289a26e1b8 ("kunit: fix debugfs code to use enum kunit_status, not bool")
---
 lib/kunit/debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c
index 9d167adfa746..382706dfb47d 100644
--- a/lib/kunit/debugfs.c
+++ b/lib/kunit/debugfs.c
@@ -60,12 +60,14 @@ static void debugfs_print_result(struct seq_file *seq, struct string_stream *log
 static int debugfs_print_results(struct seq_file *seq, void *v)
 {
 	struct kunit_suite *suite = (struct kunit_suite *)seq->private;
-	enum kunit_status success = kunit_suite_has_succeeded(suite);
+	enum kunit_status success;
 	struct kunit_case *test_case;
 
 	if (!suite)
 		return 0;
 
+	success = kunit_suite_has_succeeded(suite);
+
 	/* Print KTAP header so the debugfs log can be parsed as valid KTAP. */
 	seq_puts(seq, "KTAP version 1\n");
 	seq_puts(seq, "1..1\n");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RESEND] kunit: debugfs: Fix unchecked dereference in debugfs_print_results()
  2023-10-30 10:47 [PATCH RESEND] kunit: debugfs: Fix unchecked dereference in debugfs_print_results() Richard Fitzgerald
@ 2023-11-30 20:57 ` Rae Moar
  0 siblings, 0 replies; 2+ messages in thread
From: Rae Moar @ 2023-11-30 20:57 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: brendan.higgins, davidgow, linux-kselftest, kunit-dev,
	linux-kernel, patches, Dan Carpenter

On Mon, Oct 30, 2023 at 6:48 AM Richard Fitzgerald
<rf@opensource.cirrus.com> wrote:
>
> Move the call to kunit_suite_has_succeeded() after the check that
> the kunit_suite pointer is valid.
>
> This was found by smatch:
>
>  lib/kunit/debugfs.c:66 debugfs_print_results() warn: variable
>  dereferenced before check 'suite' (see line 63)
>
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: 38289a26e1b8 ("kunit: fix debugfs code to use enum kunit_status, not bool")

Hello!

This patch looks good to me! Thanks for fixing this!

Reviewed-by: Rae Moar <rmoar@google.com>

-Rae

> ---
>  lib/kunit/debugfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c
> index 9d167adfa746..382706dfb47d 100644
> --- a/lib/kunit/debugfs.c
> +++ b/lib/kunit/debugfs.c
> @@ -60,12 +60,14 @@ static void debugfs_print_result(struct seq_file *seq, struct string_stream *log
>  static int debugfs_print_results(struct seq_file *seq, void *v)
>  {
>         struct kunit_suite *suite = (struct kunit_suite *)seq->private;
> -       enum kunit_status success = kunit_suite_has_succeeded(suite);
> +       enum kunit_status success;
>         struct kunit_case *test_case;
>
>         if (!suite)
>                 return 0;
>
> +       success = kunit_suite_has_succeeded(suite);
> +
>         /* Print KTAP header so the debugfs log can be parsed as valid KTAP. */
>         seq_puts(seq, "KTAP version 1\n");
>         seq_puts(seq, "1..1\n");
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-30 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 10:47 [PATCH RESEND] kunit: debugfs: Fix unchecked dereference in debugfs_print_results() Richard Fitzgerald
2023-11-30 20:57 ` Rae Moar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox