diff mbox series

[5.4,03/74] module: merge repetitive strings in module_sig_check()

Message ID 20210405085024.812932452@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg Kroah-Hartman April 5, 2021, 8:53 a.m. UTC
From: Sergey Shtylyov <s.shtylyov@omprussia.ru>

[ Upstream commit 705e9195187d85249fbb0eaa844b1604a98fbc9a ]

The 'reason' variable in module_sig_check() points to 3 strings across
the *switch* statement, all needlessly starting with the same text.
Let's put the starting text into the pr_notice() call -- it saves 21
bytes of the object code (x86 gcc 10.2.1).

Suggested-by: Joe Perches <joe@perches.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Sergey Shtylyov <s.shtylyov@omprussia.ru>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/module.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Greg Kroah-Hartman April 5, 2021, 1:40 p.m. UTC | #1
On Mon, Apr 05, 2021 at 04:35:40PM +0300, Sergey Shtylyov wrote:
> On 4/5/21 11:53 AM, Greg Kroah-Hartman wrote:
> 
> > From: Sergey Shtylyov <s.shtylyov@omprussia.ru>
> > 
> > [ Upstream commit 705e9195187d85249fbb0eaa844b1604a98fbc9a ]
> > 
> > The 'reason' variable in module_sig_check() points to 3 strings across
> > the *switch* statement, all needlessly starting with the same text.
> > Let's put the starting text into the pr_notice() call -- it saves 21
> > bytes of the object code (x86 gcc 10.2.1).
> > 
> > Suggested-by: Joe Perches <joe@perches.com>
> > Reviewed-by: Miroslav Benes <mbenes@suse.cz>
> > Signed-off-by: Sergey Shtylyov <s.shtylyov@omprussia.ru>
> > Signed-off-by: Jessica Yu <jeyu@kernel.org>
> > Signed-off-by: Sasha Levin <sashal@kernel.org>
> > ---
> >  kernel/module.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/kernel/module.c b/kernel/module.c
> > index ab1f97cfe18d..9fe3e9b85348 100644
> > --- a/kernel/module.c
> > +++ b/kernel/module.c
> > @@ -2908,16 +2908,17 @@ static int module_sig_check(struct load_info *info, int flags)
> >  		 * enforcing, certain errors are non-fatal.
> >  		 */
> >  	case -ENODATA:
> > -		reason = "Loading of unsigned module";
> > +		reason = "unsigned module";
> >  		goto decide;
> >  	case -ENOPKG:
> > -		reason = "Loading of module with unsupported crypto";
> > +		reason = "module with unsupported crypto";
> >  		goto decide;
> >  	case -ENOKEY:
> > -		reason = "Loading of module with unavailable key";
> > +		reason = "module with unavailable key";
> >  	decide:
> >  		if (is_module_sig_enforced()) {
> > -			pr_notice("%s is rejected\n", reason);
> > +			pr_notice("%s: loading of %s is rejected\n",
> > +				  info->name, reason);
> 
>    Mhm, in 5.4 there was no printing of 'info->name'...

Is that now a problem?

thanks,

greg k-h
Sergey Shtylyov April 5, 2021, 2:11 p.m. UTC | #2
On 4/5/21 4:40 PM, Greg Kroah-Hartman wrote:

[...]
>>> [ Upstream commit 705e9195187d85249fbb0eaa844b1604a98fbc9a ]
>>>
>>> The 'reason' variable in module_sig_check() points to 3 strings across
>>> the *switch* statement, all needlessly starting with the same text.
>>> Let's put the starting text into the pr_notice() call -- it saves 21
>>> bytes of the object code (x86 gcc 10.2.1).
>>>
>>> Suggested-by: Joe Perches <joe@perches.com>
>>> Reviewed-by: Miroslav Benes <mbenes@suse.cz>
>>> Signed-off-by: Sergey Shtylyov <s.shtylyov@omprussia.ru>
>>> Signed-off-by: Jessica Yu <jeyu@kernel.org>
>>> Signed-off-by: Sasha Levin <sashal@kernel.org>
>>> ---
>>>  kernel/module.c | 9 +++++----
>>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/kernel/module.c b/kernel/module.c
>>> index ab1f97cfe18d..9fe3e9b85348 100644
>>> --- a/kernel/module.c
>>> +++ b/kernel/module.c
>>> @@ -2908,16 +2908,17 @@ static int module_sig_check(struct load_info *info, int flags)
>>>  		 * enforcing, certain errors are non-fatal.
>>>  		 */
>>>  	case -ENODATA:
>>> -		reason = "Loading of unsigned module";
>>> +		reason = "unsigned module";
>>>  		goto decide;
>>>  	case -ENOPKG:
>>> -		reason = "Loading of module with unsupported crypto";
>>> +		reason = "module with unsupported crypto";
>>>  		goto decide;
>>>  	case -ENOKEY:
>>> -		reason = "Loading of module with unavailable key";
>>> +		reason = "module with unavailable key";
>>>  	decide:
>>>  		if (is_module_sig_enforced()) {
>>> -			pr_notice("%s is rejected\n", reason);
>>> +			pr_notice("%s: loading of %s is rejected\n",
>>> +				  info->name, reason);
>>
>>    Mhm, in 5.4 there was no printing of 'info->name'...
> 
> Is that now a problem?

   Looking at 5.4.y, it probably shouldn't be a problem... but I had to go and look. :-)
   I've found a simple commit that added 'info->name' printing (perhaps should also be
considered for inclusion?):

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e9f35f634e099894f4d6c3b039cd3de5281ee637


> thanks,
> 
> greg k-h

MBR, Sergey
diff mbox series

Patch

diff --git a/kernel/module.c b/kernel/module.c
index ab1f97cfe18d..9fe3e9b85348 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2908,16 +2908,17 @@  static int module_sig_check(struct load_info *info, int flags)
 		 * enforcing, certain errors are non-fatal.
 		 */
 	case -ENODATA:
-		reason = "Loading of unsigned module";
+		reason = "unsigned module";
 		goto decide;
 	case -ENOPKG:
-		reason = "Loading of module with unsupported crypto";
+		reason = "module with unsupported crypto";
 		goto decide;
 	case -ENOKEY:
-		reason = "Loading of module with unavailable key";
+		reason = "module with unavailable key";
 	decide:
 		if (is_module_sig_enforced()) {
-			pr_notice("%s is rejected\n", reason);
+			pr_notice("%s: loading of %s is rejected\n",
+				  info->name, reason);
 			return -EKEYREJECTED;
 		}