Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6009157imu; Wed, 30 Jan 2019 07:17:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN6NesmdS8oRlCiEHte4W/n4yIg2DdKlRYk2P6f3b/vUYcyzUnevLnFIg1IXOoV1L8zxPhsf X-Received: by 2002:a63:9a09:: with SMTP id o9mr26798698pge.94.1548861471885; Wed, 30 Jan 2019 07:17:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548861471; cv=none; d=google.com; s=arc-20160816; b=zPKDXHB8SvYSwn6aLC/OEwaSqYdHEwnkMQYNXKuARxZHVJKDviFGjZ3DUqXwmgPVNa f9W0PV9m40N0Ly0PjuWaJH//exK5m83SHW1pRoyWbfnGzAT0Hl/EQ3qrR1plNojKq1bi WheQPDMVzXx7acCs+6m2fRBPTmA7sw/lmnPiGU9ENObREaoFj1pR2dc5e513V1Uor7G/ cmXCsxAxEY36zHzbirqVQm5oS8DBOyRNFVYlzleewmdAs3RdyoEDzyLrpVJHdCsipARP Zo8h3rGnRrr0sJlfeAHe3WYI1RHU4PtsQSDrN+Z0WZn6C3SPeJ50kjiQzqLwOdiuNMsm ZS4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JNE5nphkjluiVOI1sfaIPK6RlGflVhC/6XUKKrRGpHM=; b=pAuSNTNdlndVTkzrbnd4eAmgTiHbh1BFWQwY8LsWxcSD51S1Es6HtfZ7p4t6H2hjrD EiMo5cRnsvLJFT8xC0DFazyNiFoAuTUJn2HFo2KuX5Oor51VXQQ7o9eJoyOOdJyRaueR UR4iEot0iL3UmYf3otPzD6bHhIc1jUeo38jgzJ7qSgksiEjkgEHwbr4Nmv6P1dnpmE1i 4wmkxadNw3/QW1MypVqskLnRpJXVRON7XgqVvCTq/4rAhUKFDNEhy/Dakxy0JsHzypch qaRz/+64FYsUpLVCP7RXjkYisGE9uNfO8oIgVbyqn44IbfIapyW9GRu5ZCl2jevdXoTX o6Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mok.nu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x128si1820303pfb.128.2019.01.30.07.17.31; Wed, 30 Jan 2019 07:17:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mok.nu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731461AbfA3PPH (ORCPT + 99 others); Wed, 30 Jan 2019 10:15:07 -0500 Received: from proxy03.fsdata.se ([89.221.252.213]:61270 "EHLO mail-gw01.fsdata.se" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726332AbfA3PPH (ORCPT ); Wed, 30 Jan 2019 10:15:07 -0500 Received: from localhost (94.234.42.28) by DAG01.HMC.local (192.168.46.11) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 30 Jan 2019 16:14:56 +0100 From: Mattias Jacobsson <2pi@mok.nu> To: , , , , CC: <2pi@mok.nu>, , Subject: [PATCH v3 2/3] platform/x86: wmi: add WMI support to MODULE_DEVICE_TABLE() Date: Wed, 30 Jan 2019 16:14:39 +0100 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [94.234.42.28] X-ClientProxiedBy: PROXY04.HMC.local (192.168.46.54) To DAG01.HMC.local (192.168.46.11) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Mattias Jacobsson <2pi@mok.nu> --- What do you think about this usage of snprintf()? Now we check if there is an error or if the printed string tried to exceeded the buffer. Ideally 500 should be a macro or a parameter, but there isn't one available. The number 500 comes from a few lines below in the function do_table(). scripts/mod/devicetable-offsets.c | 3 +++ scripts/mod/file2alias.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) 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..abaa6c090564 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -37,6 +37,7 @@ typedef unsigned char __u8; typedef struct { __u8 b[16]; } uuid_le; +#define UUID_STRING_LEN 36 /* Big exception to the "don't include kernel headers into userspace, which * even potentially has different endianness and word sizes, since @@ -1287,6 +1288,26 @@ 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) != UUID_STRING_LEN) { + warn("Invalid WMI device id 'wmi:%s' in '%s'\n", + *guid_string, filename); + return 0; + } + + int len = snprintf(alias, 500, WMI_MODULE_PREFIX "%s", *guid_string); + + if (len < 0 || len >= 500) { + 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 +1378,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. -- 2.20.1