Bug 227735 - sched_setscheduler returns EPERM instead of EINVAL when sched_priority is out of range
Summary: sched_setscheduler returns EPERM instead of EINVAL when sched_priority is out...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.1-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: Mitchell Horne
URL:
Keywords: easy, needs-qa
Depends on:
Blocks:
 
Reported: 2018-04-24 06:03 UTC by Ali Abdallah
Modified: 2022-10-25 14:39 UTC (History)
3 users (show)

See Also:


Attachments
Proposed patch to fix the return value (935 bytes, patch)
2022-08-26 20:27 UTC, Ali Abdallah
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Abdallah 2018-04-24 06:03:04 UTC
According to the documentation of sched_setscheduler, [EINVAL] should be returned if the value of the policy argument is invalid, or one or more parameters contained in param is outside the valid range.

In ksched.c line 180, the ksched_setscheduler functions returns EPERM when
the check (param->sched_priority >= P1B_PRIO_MIN && param->sched_priority <=
P1B_PRIO_MAX) fails, It should return EINVAL instead.

This is a minor issue, but I think it should be fixed.
Comment 1 Ali Abdallah 2022-08-26 20:27:23 UTC
Created attachment 236134 [details]
Proposed patch to fix the return value

Any change to get this minor issu fixed?
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-10-17 18:13:58 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ba4782022ac840bd20f4e10cb95ca27d2742333a

commit ba4782022ac840bd20f4e10cb95ca27d2742333a
Author:     Ali Abdallah <ali.abdallah@suse.com>
AuthorDate: 2022-10-17 18:11:48 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-17 18:12:13 +0000

    ksched: correct return code for invalid priority

    By convention, EINVAL is returned when validating arguments, not EPERM.
    This matches the documented behaviour of sched_setscheduler(3), and that
    of SCHED_OTHER.

    PR:             227735
    MFC after:      1 week
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D37021

 sys/kern/ksched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-10-24 15:54:36 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3097c0500581151732e5d7a20bdd4e3997cab2d5

commit 3097c0500581151732e5d7a20bdd4e3997cab2d5
Author:     Ali Abdallah <ali.abdallah@suse.com>
AuthorDate: 2022-10-17 18:11:48 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-24 15:53:11 +0000

    ksched: correct return code for invalid priority

    By convention, EINVAL is returned when validating arguments, not EPERM.
    This matches the documented behaviour of sched_setscheduler(3), and that
    of SCHED_OTHER.

    PR:             227735
    MFC after:      1 week
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D37021

    (cherry picked from commit ba4782022ac840bd20f4e10cb95ca27d2742333a)

 sys/kern/ksched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-10-24 15:58:39 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a55b3c12a88476e5cfb65ac3c88aebc17015a82f

commit a55b3c12a88476e5cfb65ac3c88aebc17015a82f
Author:     Ali Abdallah <ali.abdallah@suse.com>
AuthorDate: 2022-10-17 18:11:48 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-24 15:56:13 +0000

    ksched: correct return code for invalid priority

    By convention, EINVAL is returned when validating arguments, not EPERM.
    This matches the documented behaviour of sched_setscheduler(3), and that
    of SCHED_OTHER.

    PR:             227735
    MFC after:      1 week
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D37021

    (cherry picked from commit ba4782022ac840bd20f4e10cb95ca27d2742333a)

 sys/kern/ksched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)