Message ID | 680df320c7263bdd35f87794ae12fb9a9ef3b71c.1548610407.git.2pi@mok.nu (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Darren Hart |
Headers | show |
Series | platform/x86: wmi: add WMI support to MODULE_DEVICE_TABLE() | expand |
On Sun, Jan 27, 2019 at 9:04 PM Mattias Jacobsson <2pi@mok.nu> wrote: > > The kernel provides the macro MODULE_DEVICE_TABLE() where driver authors > can specify their device type and their array of device_ids and thereby > trigger the generation of the appropriate MODULE_ALIAS() output. This is > opposed to having to specify one MODULE_ALIAS() for each device. The WMI > device type is currently not supported. > > While using MODULE_DEVICE_TABLE() does increase the complexity as well > as spreading out the implementation across the kernel, it does come with > some benefits too; > * It makes different drivers look more similar; if you can specify the > array of device_ids any device type specific input to MODULE_ALIAS() > will automatically be generated for you. > * It helps each driver avoid keeping multiple versions of the same > information in sync. That is, both the array of device_ids and the > potential multitude of MODULE_ALIAS()'s. > > Add WMI support to MODULE_DEVICE_TABLE() by adding info about struct > wmi_device_id in devicetable-offsets.c and add a WMI entry point in > file2alias.c. > > The type argument for MODULE_DEVICE_TABLE(type, name) is wmi. > +/* Looks like: wmi:guid */ > +static int do_wmi_entry(const char *filename, void *symval, char *alias) > +{ > + DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); > + if (strlen(*guid_string) != WMI_GUID_STRING_LEN) { > + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", > + *guid_string, filename); > + return 0; > + } > + if (snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { What the point to use snprintf here with arbitrary buffer size if we exactly know 2 facts: 1. UUID string is 36 characters 2. buffer is long enough ? > + warn("Could not generate all MODULE_ALIAS's in '%s'\n", > + filename); > + return 0; > + } > + return 1; > +}
Hi, On 2019-01-27, Andy Shevchenko wrote: > On Sun, Jan 27, 2019 at 9:04 PM Mattias Jacobsson <2pi@mok.nu> wrote: > > > > The kernel provides the macro MODULE_DEVICE_TABLE() where driver authors > > can specify their device type and their array of device_ids and thereby > > trigger the generation of the appropriate MODULE_ALIAS() output. This is > > opposed to having to specify one MODULE_ALIAS() for each device. The WMI > > device type is currently not supported. > > > > While using MODULE_DEVICE_TABLE() does increase the complexity as well > > as spreading out the implementation across the kernel, it does come with > > some benefits too; > > * It makes different drivers look more similar; if you can specify the > > array of device_ids any device type specific input to MODULE_ALIAS() > > will automatically be generated for you. > > * It helps each driver avoid keeping multiple versions of the same > > information in sync. That is, both the array of device_ids and the > > potential multitude of MODULE_ALIAS()'s. > > > > Add WMI support to MODULE_DEVICE_TABLE() by adding info about struct > > wmi_device_id in devicetable-offsets.c and add a WMI entry point in > > file2alias.c. > > > > The type argument for MODULE_DEVICE_TABLE(type, name) is wmi. > > > +/* Looks like: wmi:guid */ > > +static int do_wmi_entry(const char *filename, void *symval, char *alias) > > +{ > > + DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); > > + if (strlen(*guid_string) != WMI_GUID_STRING_LEN) { > > + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", > > + *guid_string, filename); > > + return 0; > > + } > > > + if (snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { > > What the point to use snprintf here with arbitrary buffer size if we > exactly know 2 facts: > 1. UUID string is 36 characters > 2. buffer is long enough > > ? As long as no one changes the code, not much. > > > + warn("Could not generate all MODULE_ALIAS's in '%s'\n", > > + filename); > > + return 0; > > + } > > + return 1; > > +} > > -- > With Best Regards, > Andy Shevchenko Thanks, Mattias
On Monday 28 January 2019 15:09:11 Mattias Jacobsson wrote: > Hi, > > On 2019-01-27, Andy Shevchenko wrote: > > On Sun, Jan 27, 2019 at 9:04 PM Mattias Jacobsson <2pi@mok.nu> wrote: > > > > > > The kernel provides the macro MODULE_DEVICE_TABLE() where driver authors > > > can specify their device type and their array of device_ids and thereby > > > trigger the generation of the appropriate MODULE_ALIAS() output. This is > > > opposed to having to specify one MODULE_ALIAS() for each device. The WMI > > > device type is currently not supported. > > > > > > While using MODULE_DEVICE_TABLE() does increase the complexity as well > > > as spreading out the implementation across the kernel, it does come with > > > some benefits too; > > > * It makes different drivers look more similar; if you can specify the > > > array of device_ids any device type specific input to MODULE_ALIAS() > > > will automatically be generated for you. > > > * It helps each driver avoid keeping multiple versions of the same > > > information in sync. That is, both the array of device_ids and the > > > potential multitude of MODULE_ALIAS()'s. > > > > > > Add WMI support to MODULE_DEVICE_TABLE() by adding info about struct > > > wmi_device_id in devicetable-offsets.c and add a WMI entry point in > > > file2alias.c. > > > > > > The type argument for MODULE_DEVICE_TABLE(type, name) is wmi. > > > > > +/* Looks like: wmi:guid */ > > > +static int do_wmi_entry(const char *filename, void *symval, char *alias) > > > +{ > > > + DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); > > > + if (strlen(*guid_string) != WMI_GUID_STRING_LEN) { > > > + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", > > > + *guid_string, filename); > > > + return 0; > > > + } > > > > > + if (snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { > > > > What the point to use snprintf here with arbitrary buffer size if we > > exactly know 2 facts: > > 1. UUID string is 36 characters > > 2. buffer is long enough > > > > ? > > As long as no one changes the code, not much. At least instead of hardcoded number 500, you should use pass size of alias: static int do_wmi_entry(const char *filename, void *symval, char *alias, size_t alias_size) if (snprintf(alias, alias_size, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { Or pass buffer of constant size and then you do not need to use snprintf: #define ALIAS_SIZE (sizeof(WMI_MODULE_PREFIX)+WMI_GUID_STRING_LEN) static int do_wmi_entry(const char *filename, void *symval, char alias[ALIAS_SIZE]) This should not break even when code around changes. > > > > > + warn("Could not generate all MODULE_ALIAS's in '%s'\n", > > > + filename); > > > + return 0; > > > + } > > > + return 1; > > > +} > > > > -- > > With Best Regards, > > Andy Shevchenko > > Thanks, > Mattias
On 2019-01-28, Pali Rohár wrote: > On Monday 28 January 2019 15:09:11 Mattias Jacobsson wrote: > > Hi, > > > > On 2019-01-27, Andy Shevchenko wrote: > > > On Sun, Jan 27, 2019 at 9:04 PM Mattias Jacobsson <2pi@mok.nu> wrote: > > > > > > > > The kernel provides the macro MODULE_DEVICE_TABLE() where driver authors > > > > can specify their device type and their array of device_ids and thereby > > > > trigger the generation of the appropriate MODULE_ALIAS() output. This is > > > > opposed to having to specify one MODULE_ALIAS() for each device. The WMI > > > > device type is currently not supported. > > > > > > > > While using MODULE_DEVICE_TABLE() does increase the complexity as well > > > > as spreading out the implementation across the kernel, it does come with > > > > some benefits too; > > > > * It makes different drivers look more similar; if you can specify the > > > > array of device_ids any device type specific input to MODULE_ALIAS() > > > > will automatically be generated for you. > > > > * It helps each driver avoid keeping multiple versions of the same > > > > information in sync. That is, both the array of device_ids and the > > > > potential multitude of MODULE_ALIAS()'s. > > > > > > > > Add WMI support to MODULE_DEVICE_TABLE() by adding info about struct > > > > wmi_device_id in devicetable-offsets.c and add a WMI entry point in > > > > file2alias.c. > > > > > > > > The type argument for MODULE_DEVICE_TABLE(type, name) is wmi. > > > > > > > +/* Looks like: wmi:guid */ > > > > +static int do_wmi_entry(const char *filename, void *symval, char *alias) > > > > +{ > > > > + DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); > > > > + if (strlen(*guid_string) != WMI_GUID_STRING_LEN) { > > > > + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", > > > > + *guid_string, filename); > > > > + return 0; > > > > + } > > > > > > > + if (snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { > > > > > > What the point to use snprintf here with arbitrary buffer size if we > > > exactly know 2 facts: > > > 1. UUID string is 36 characters > > > 2. buffer is long enough > > > > > > ? > > > > As long as no one changes the code, not much. > > At least instead of hardcoded number 500, you should use pass size of alias: Just a note; 500 comes from a few lines below in the do_table() function. It is the actual size of alias we get in do_wmi_entry(). > > static int do_wmi_entry(const char *filename, void *symval, char *alias, size_t alias_size) > > if (snprintf(alias, alias_size, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { That is a good idea, but requires changing all other entry points. I was thinking of defining a DO_ENTRY_ALIAS_SIZE macro to replace all/any 500 in file2alias.c. However that is a separate patch. > > Or pass buffer of constant size and then you do not need to use snprintf: > > #define ALIAS_SIZE (sizeof(WMI_MODULE_PREFIX)+WMI_GUID_STRING_LEN) I could use ALIAS_SIZE and add that to snprintf() instead of 500. While I guess it is unlikely that alias ever will be changed to be too short for us, using ALIAS_SIZE doesn't "guarantee" that we are within the bounds of alias if anything changes. > > static int do_wmi_entry(const char *filename, void *symval, char alias[ALIAS_SIZE]) > > This should not break even when code around changes. > > > > > > > > + warn("Could not generate all MODULE_ALIAS's in '%s'\n", > > > > + filename); > > > > + return 0; > > > > + } > > > > + return 1; > > > > +} > > > > > > -- > > > With Best Regards, > > > Andy Shevchenko > > > > Thanks, > > Mattias > > -- > Pali Rohár > pali.rohar@gmail.com Thanks, Mattias
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c index 293004499b4d..99276a422e77 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -225,5 +225,8 @@ int main(void) DEVID_FIELD(typec_device_id, svid); DEVID_FIELD(typec_device_id, mode); + DEVID(wmi_device_id); + DEVID_FIELD(wmi_device_id, guid_string); + return 0; } diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index a37af7d71973..f014a2466ff7 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1287,6 +1287,23 @@ static int do_typec_entry(const char *filename, void *symval, char *alias) return 1; } +/* Looks like: wmi:guid */ +static int do_wmi_entry(const char *filename, void *symval, char *alias) +{ + DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); + if (strlen(*guid_string) != WMI_GUID_STRING_LEN) { + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", + *guid_string, filename); + return 0; + } + if (snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string) < 0) { + warn("Could not generate all MODULE_ALIAS's in '%s'\n", + filename); + return 0; + } + return 1; +} + /* Does namelen bytes of name exactly match the symbol? */ static bool sym_is(const char *name, unsigned namelen, const char *symbol) { @@ -1357,6 +1374,7 @@ static const struct devtable devtable[] = { {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry}, {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry}, {"typec", SIZE_typec_device_id, do_typec_entry}, + {"wmi", SIZE_wmi_device_id, do_wmi_entry}, }; /* Create MODULE_ALIAS() statements.
The kernel provides the macro MODULE_DEVICE_TABLE() where driver authors can specify their device type and their array of device_ids and thereby trigger the generation of the appropriate MODULE_ALIAS() output. This is opposed to having to specify one MODULE_ALIAS() for each device. The WMI device type is currently not supported. While using MODULE_DEVICE_TABLE() does increase the complexity as well as spreading out the implementation across the kernel, it does come with some benefits too; * It makes different drivers look more similar; if you can specify the array of device_ids any device type specific input to MODULE_ALIAS() will automatically be generated for you. * It helps each driver avoid keeping multiple versions of the same information in sync. That is, both the array of device_ids and the potential multitude of MODULE_ALIAS()'s. Add WMI support to MODULE_DEVICE_TABLE() by adding info about struct wmi_device_id in devicetable-offsets.c and add a WMI entry point in file2alias.c. The type argument for MODULE_DEVICE_TABLE(type, name) is wmi. Suggested-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Mattias Jacobsson <2pi@mok.nu> --- scripts/mod/devicetable-offsets.c | 3 +++ scripts/mod/file2alias.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+)