rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* module parameters permission
@ 2021-04-29  9:58 Fabio Aiuto
  2021-04-29 10:05 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Fabio Aiuto @ 2021-04-29  9:58 UTC (permalink / raw)
  To: rust-for-linux; +Cc: linux-kernel

Hi all,

I'm trying to declare module parameters this way:


   params: {
        scull_major: i32 {
            default: 0,
            permissions: bindings::S_IRUGO as i32,
            description: b"Major number",
        },
        scull_minor: i32 {
            default: 0,
            permissions: bindings::S_IRUGO as i32,
            description: b"Minor number",
        },

i.e. using S_IRUGO macro exposed by bindgen. But I have the
following compiler error:

error: proc macro panicked
  --> samples/rust/rust_scull.rs:12:1
   |
12 | / module! {
13 | |     type: RustScull,
14 | |     name: b"rust_scull",
15 | |     author: b"Alessandro Rubini, Jonathan Corbet",
...  |
44 | |     },
45 | | }
   | |_^
   |
   = help: message: Expected Literal

the same if I remove as i32 casts.

if I write permissions as in samples/rust/rust_module_parameters.rs

    params: {
        my_bool: bool {
            default: true,
            permissions: 0,
            description: b"Example of bool",
        },
        my_i32: i32 {
            default: 42,
            permissions: 0o644, <-------
            description: b"Example of i32",
        },

I get no error.

What's the right way to use S_I*UGO macros?

my includes are:

// SPDX-License-Identifier: GPL-2.0

//! Scull driver sample

#![no_std]
#![feature(allocator_api, global_asm)]

use kernel::prelude::*;
use kernel::{chrdev, cstr};
use crate::bindings;

thank you,

fabio



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

* Re: module parameters permission
  2021-04-29  9:58 module parameters permission Fabio Aiuto
@ 2021-04-29 10:05 ` Greg KH
  2021-04-29 10:25   ` Fabio Aiuto
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2021-04-29 10:05 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: rust-for-linux, linux-kernel

On Thu, Apr 29, 2021 at 11:58:20AM +0200, Fabio Aiuto wrote:
> Hi all,
> 
> I'm trying to declare module parameters this way:
> 
> 
>    params: {
>         scull_major: i32 {
>             default: 0,
>             permissions: bindings::S_IRUGO as i32,
>             description: b"Major number",
>         },
>         scull_minor: i32 {
>             default: 0,
>             permissions: bindings::S_IRUGO as i32,
>             description: b"Minor number",
>         },
> 
> i.e. using S_IRUGO macro exposed by bindgen. But I have the
> following compiler error:
> 
> error: proc macro panicked
>   --> samples/rust/rust_scull.rs:12:1
>    |
> 12 | / module! {
> 13 | |     type: RustScull,
> 14 | |     name: b"rust_scull",
> 15 | |     author: b"Alessandro Rubini, Jonathan Corbet",
> ...  |
> 44 | |     },
> 45 | | }
>    | |_^
>    |
>    = help: message: Expected Literal
> 
> the same if I remove as i32 casts.
> 
> if I write permissions as in samples/rust/rust_module_parameters.rs
> 
>     params: {
>         my_bool: bool {
>             default: true,
>             permissions: 0,
>             description: b"Example of bool",
>         },
>         my_i32: i32 {
>             default: 42,
>             permissions: 0o644, <-------
>             description: b"Example of i32",
>         },
> 
> I get no error.
> 
> What's the right way to use S_I*UGO macros?

Not at all, use the octal values instead please.

That's the way that we have declared a while ago, and I think
checkpatch.pl will even catch if you try to do this in any new code.
Please don't force us to deal with S_* defines in rust code as well.

thanks,

greg k-h

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

* Re: module parameters permission
  2021-04-29 10:05 ` Greg KH
@ 2021-04-29 10:25   ` Fabio Aiuto
  2021-04-29 11:26     ` Adam Bratschi-Kaye
  2021-04-29 11:26     ` Finn Behrens
  0 siblings, 2 replies; 5+ messages in thread
From: Fabio Aiuto @ 2021-04-29 10:25 UTC (permalink / raw)
  To: Greg KH; +Cc: rust-for-linux, linux-kernel

On Thu, Apr 29, 2021 at 12:05:08PM +0200, Greg KH wrote:
> On Thu, Apr 29, 2021 at 11:58:20AM +0200, Fabio Aiuto wrote:
> > Hi all,
> > 
> > I'm trying to declare module parameters this way:
> > 
> > 
> >    params: {
> >         scull_major: i32 {
> >             default: 0,
> >             permissions: bindings::S_IRUGO as i32,
> >             description: b"Major number",
> >         },
> >         scull_minor: i32 {
> >             default: 0,
> >             permissions: bindings::S_IRUGO as i32,
> >             description: b"Minor number",
> >         },
> > 
> > i.e. using S_IRUGO macro exposed by bindgen. But I have the
> > following compiler error:
> > 
> > error: proc macro panicked
> >   --> samples/rust/rust_scull.rs:12:1
> >    |
> > 12 | / module! {
> > 13 | |     type: RustScull,
> > 14 | |     name: b"rust_scull",
> > 15 | |     author: b"Alessandro Rubini, Jonathan Corbet",
> > ...  |
> > 44 | |     },
> > 45 | | }
> >    | |_^
> >    |
> >    = help: message: Expected Literal
> > 
> > the same if I remove as i32 casts.
> > 
> > if I write permissions as in samples/rust/rust_module_parameters.rs
> > 
> >     params: {
> >         my_bool: bool {
> >             default: true,
> >             permissions: 0,
> >             description: b"Example of bool",
> >         },
> >         my_i32: i32 {
> >             default: 42,
> >             permissions: 0o644, <-------
> >             description: b"Example of i32",
> >         },
> > 
> > I get no error.
> > 
> > What's the right way to use S_I*UGO macros?
> 
> Not at all, use the octal values instead please.
> 
> That's the way that we have declared a while ago, and I think
> checkpatch.pl will even catch if you try to do this in any new code.
> Please don't force us to deal with S_* defines in rust code as well.
> 
> thanks,
> 
> greg k-h

thank you I didn't know that. I will use octal than.

Anyway I'd like to know what was the matter with those bindings...

fabio

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

* Re: module parameters permission
  2021-04-29 10:25   ` Fabio Aiuto
@ 2021-04-29 11:26     ` Adam Bratschi-Kaye
  2021-04-29 11:26     ` Finn Behrens
  1 sibling, 0 replies; 5+ messages in thread
From: Adam Bratschi-Kaye @ 2021-04-29 11:26 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: Greg KH, rust-for-linux

> Anyway I'd like to know what was the matter with those bindings...

There's nothing wrong with the bindings, the problem is that the
`module!` procedural macro will only parse a literal for the
permissions field. Given Greg's comment I don't think it's much of an
issue, but there's the same problem for other fields which it would be
nice to fix (e.g. your example works with the default parameter value
`42`, but will hit the same parse error if you instead had `40 + 2`).
We discussed it a bit here:
https://github.com/Rust-for-Linux/linux/issues/11#issuecomment-778569067
.

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

* Re: module parameters permission
  2021-04-29 10:25   ` Fabio Aiuto
  2021-04-29 11:26     ` Adam Bratschi-Kaye
@ 2021-04-29 11:26     ` Finn Behrens
  1 sibling, 0 replies; 5+ messages in thread
From: Finn Behrens @ 2021-04-29 11:26 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: Greg KH, rust-for-linux, linux-kernel

The module macro is a proc_macro. This is written in a way to only accept one single iteral at that position. So that is an expected behaviour with the current implementation.
If needed, this macro could be extended with functionality to deal with that case, but if octal values are preferred, I don’t see a reason to introduce that level of complexity.

Finn

> On 29. Apr 2021, at 12:25, Fabio Aiuto <fabioaiuto83@gmail.com> wrote:
> 
> On Thu, Apr 29, 2021 at 12:05:08PM +0200, Greg KH wrote:
>> On Thu, Apr 29, 2021 at 11:58:20AM +0200, Fabio Aiuto wrote:
>>> Hi all,
>>> 
>>> I'm trying to declare module parameters this way:
>>> 
>>> 
>>>   params: {
>>>        scull_major: i32 {
>>>            default: 0,
>>>            permissions: bindings::S_IRUGO as i32,
>>>            description: b"Major number",
>>>        },
>>>        scull_minor: i32 {
>>>            default: 0,
>>>            permissions: bindings::S_IRUGO as i32,
>>>            description: b"Minor number",
>>>        },
>>> 
>>> i.e. using S_IRUGO macro exposed by bindgen. But I have the
>>> following compiler error:
>>> 
>>> error: proc macro panicked
>>>  --> samples/rust/rust_scull.rs:12:1
>>>   |
>>> 12 | / module! {
>>> 13 | |     type: RustScull,
>>> 14 | |     name: b"rust_scull",
>>> 15 | |     author: b"Alessandro Rubini, Jonathan Corbet",
>>> ...  |
>>> 44 | |     },
>>> 45 | | }
>>>   | |_^
>>>   |
>>>   = help: message: Expected Literal
>>> 
>>> the same if I remove as i32 casts.
>>> 
>>> if I write permissions as in samples/rust/rust_module_parameters.rs
>>> 
>>>    params: {
>>>        my_bool: bool {
>>>            default: true,
>>>            permissions: 0,
>>>            description: b"Example of bool",
>>>        },
>>>        my_i32: i32 {
>>>            default: 42,
>>>            permissions: 0o644, <-------
>>>            description: b"Example of i32",
>>>        },
>>> 
>>> I get no error.
>>> 
>>> What's the right way to use S_I*UGO macros?
>> 
>> Not at all, use the octal values instead please.
>> 
>> That's the way that we have declared a while ago, and I think
>> checkpatch.pl will even catch if you try to do this in any new code.
>> Please don't force us to deal with S_* defines in rust code as well.
>> 
>> thanks,
>> 
>> greg k-h
> 
> thank you I didn't know that. I will use octal than.
> 
> Anyway I'd like to know what was the matter with those bindings...
> 
> fabio


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

end of thread, other threads:[~2021-04-29 11:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29  9:58 module parameters permission Fabio Aiuto
2021-04-29 10:05 ` Greg KH
2021-04-29 10:25   ` Fabio Aiuto
2021-04-29 11:26     ` Adam Bratschi-Kaye
2021-04-29 11:26     ` Finn Behrens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).