Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3527290imu; Mon, 28 Jan 2019 06:28:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN7ndGF3ijn/0UvMdJe4sG/M34zC3b7NnhVR9dbnCYPwa2qo3vMe4knurCwnewwJrAfjUEFw X-Received: by 2002:a63:557:: with SMTP id 84mr19592114pgf.411.1548685680281; Mon, 28 Jan 2019 06:28:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548685680; cv=none; d=google.com; s=arc-20160816; b=RMi2pFcAo/ceG6S1zbFHv0j70xu6AQAWFlFsaIE2GgXHSzwp6ICcMCjp4PbP6O0X/g kSJa4WG6eMRSy6L2rx1uRiLyfu0LypRF1aWEchrCJ5t+TGs9AXxMLJrC8QmPWTV4f7Yq QdjR0D7UL1vZbJkyAo5fDudlu+mt0ZuIGJ/2E/fyzF2WLnOijI0nmywOTJsZaExPdh21 HszcW0mAi2+U0vRktg4J99YwbQqLTYa1Z3VefBzI67tjhN6rVer+bNNPEh5VIVZZ82xz dT2Smd6XwPBB++E4G39TMzhRbirtBdTzjAN3pi0hWpxcaK1qEGLJJgoGVp9nwb5qw3vu r9Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VEvcffBWdOWN6PdoAFgZWZE1ZkFcnJULt+GhahYN0uU=; b=uhQeyN69iJmEaYS25Dy03pn1/mo5pB36r0zvoGPUF7fOiXZa0llhrbvKG5NkV8zuBO hqEZOTZ1kcHcZGSBr9t+yIdk5zjhEzAdAnnKzTzAtAiSij+3bkx+1R73YR6d6B7X/q0+ oq14ztQJC/ZycUpes8cBUEzrcKEMjV/ItytJ9oztgaHVRXSLRbgtAvQRyQIKbyiHdTKR iNpyYKxaAvof5sW/puUT89hc/gU2RzxWnaSpKxnTeCEFVP3i6b0bdCyaDpsXSPT2lTid p5lImrnOzPM7WsgVxM4Epa8bULIAUmyI9dJ92evqQaEKL7J9kJgw2hZiSzjcVT/wrBQp E7fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=m8EjYQsf; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si31246770pgd.88.2019.01.28.06.27.45; Mon, 28 Jan 2019 06:28:00 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=m8EjYQsf; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbfA1O1F (ORCPT + 99 others); Mon, 28 Jan 2019 09:27:05 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52374 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbfA1O1F (ORCPT ); Mon, 28 Jan 2019 09:27:05 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so14204536wml.2; Mon, 28 Jan 2019 06:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=VEvcffBWdOWN6PdoAFgZWZE1ZkFcnJULt+GhahYN0uU=; b=m8EjYQsfngRjsU+d70kTaJ0q5ecOtODTVnEPu+s5iDQkjiQuG6jg5c7rOvJSU7BVmi ifj8d6gvuYD6z7+LFfqqxfc1ydOKWUYbVaB/VLEnkL5jMHor+v3Zt3lpTXYxN2mh1Qag DgqobxgrhKnvAW+GhjsKVFvVLMVtNNnXTUn1P+GlF88eJ306QKcqvUVZBv5XTfeQz8Ds m5g6Zyb8uHeJ2UBF7q3VE3P+UH0Tj352gj4I6M8bnp5kMwieTtUOfA+3+DVHzcu+Rwjq +Ie5YjAq4y/rVYCmytsTkWQmqdDb6jo/dO+stM2TczLU8eH37zC05ZfprXBG2ZFWVaGd UXwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=VEvcffBWdOWN6PdoAFgZWZE1ZkFcnJULt+GhahYN0uU=; b=F8/l3eJeCWHTFR2QC938McuQ6VngGzOvHJ2e14Im0JtkSclaWI0z8578DFao2B8J1t xpdBbuEuLCGAsTfelT+957fey44Hu7+/DyzVb3ypVk2uRRnk7xaxvPiNGwRIyB9F0MoS HC6AdmtMn5SGR40IlmQ19bwcb6pjZyAYcibTO6+Sgb/z6snM2CopvzNCMQ0K9tTOntCC wIEEoJPJJgzCwcRl+lSTti/M2+o4HnmInrD9qxW5IujHEllT+2CblsyWxWae3tJDCHQF ShnAMo0qrXgetrAdl3aH1mxXPOxf2NkZAl/9buqWruSUycGi9uwKJngAGRdjxWOojW3J 0SMg== X-Gm-Message-State: AJcUukcYRNE8OrPBYhyZ2+agIO/jRj5l17UZfepNOJpLrQm2NCl5VBA1 ZSrD53IStwtrPh+5BlHV5wWGJuq+ X-Received: by 2002:a1c:dd04:: with SMTP id u4mr17288833wmg.84.1548685623197; Mon, 28 Jan 2019 06:27:03 -0800 (PST) Received: from pali ([2a02:2b88:2:1::5cc6:2f]) by smtp.gmail.com with ESMTPSA id n9sm91391088wrx.80.2019.01.28.06.27.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 06:27:02 -0800 (PST) Date: Mon, 28 Jan 2019 15:27:01 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Mattias Jacobsson <2pi@mok.nu> Cc: Andy Shevchenko , Masahiro Yamada , michal.lkml@markovi.net, Darren Hart , Andy Shevchenko , Platform Driver , Linux Kernel Mailing List Subject: Re: [PATCH v2 2/3] platform/x86: wmi: add WMI support to MODULE_DEVICE_TABLE() Message-ID: <20190128142701.xj4vwiind4ddbcj6@pali> References: <680df320c7263bdd35f87794ae12fb9a9ef3b71c.1548610407.git.2pi@mok.nu> <20190128140911.xsltdctpk3bya7ya@mok.nu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190128140911.xsltdctpk3bya7ya@mok.nu> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- Pali Rohár pali.rohar@gmail.com