mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Pravin Shedge <pravin.shedge4linux@gmail.com>
Cc: fkostenzer@live.at, andriy.shevchenko@linux.intel.com,
	geert@linux-m68k.org, paul.gortmaker@windriver.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib: add module unload support to sort tests
Date: Mon, 18 Dec 2017 14:21:38 -0800	[thread overview]
Message-ID: <20171218142138.f1b84a8c1ca072b15b54af33@linux-foundation.org> (raw)
In-Reply-To: <1513504167-4118-1-git-send-email-pravin.shedge4linux@gmail.com>

On Sun, 17 Dec 2017 15:19:27 +0530 Pravin Shedge <pravin.shedge4linux@gmail.com> wrote:

> test_sort.c perform array-based and linked list sort test. Code allows to
> compile either as a loadable modules or builtin into the kernel.
> 
> Current code is not allow to unload the test_sort.ko module after
> successful completion.
> 
> This patch add support to unload the "test_sort.ko" module.
> 
> ...
>
> --- a/lib/test_sort.c
> +++ b/lib/test_sort.c
> @@ -13,11 +13,12 @@ static int __init cmpint(const void *a, const void *b)
>  
>  static int __init test_sort_init(void)
>  {
> -	int *a, i, r = 1, err = -ENOMEM;
> +	int *a, i, r = 1;
> +	int err = -EAGAIN; /* Fail will directly unload the module */
>  
>  	a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
>  	if (!a)
> -		return err;
> +		return -ENOMEM;
>  
>  	for (i = 0; i < TEST_LEN; i++) {
>  		r = (r * 725861) % 6599;
> @@ -26,13 +27,12 @@ static int __init test_sort_init(void)
>  
>  	sort(a, TEST_LEN, sizeof(*a), cmpint, NULL);
>  
> -	err = -EINVAL;
>  	for (i = 0; i < TEST_LEN-1; i++)
>  		if (a[i] > a[i+1]) {
>  			pr_err("test has failed\n");
> +			err = -EINVAL;
>  			goto exit;
>  		}
> -	err = 0;
>  	pr_info("test passed\n");
>  exit:
>  	kfree(a);

I'm struggling to understand this.

It seems that the current pattern for lib/test_*.c is:

- if test fails, module_init() handler returns -EFOO
- if test succeeds, module_init() handler returns 0

So the module will be auto-unloaded if it failed and will require an
rmmod if it succeeded.

Correct?

And it appears that lib/test_sort.c currently implements the above. 
And that your patch changes it so that the module_init() handler always
returns -EFOO, so the module will be aut-unloaded whether or not the
testing passed.

Correct?

If so, why do you think we shiould alter lib/test_sort.c to behave in
this atypical fashion?

  reply	other threads:[~2017-12-18 22:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-17  9:49 Pravin Shedge
2017-12-18 22:21 ` Andrew Morton [this message]
2017-12-19 17:40   ` Pravin Shedge
2017-12-19 22:51     ` Andrew Morton
2017-12-19 23:06       ` Randy Dunlap
2017-12-20  4:13     ` Paul Gortmaker
2017-12-21  2:05       ` Pravin Shedge
2017-12-22 18:25 ` [PATCH v2] " Pravin Shedge

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=20171218142138.f1b84a8c1ca072b15b54af33@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=fkostenzer@live.at \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=pravin.shedge4linux@gmail.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®