Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1272335rdb; Wed, 20 Sep 2023 04:56:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdJuyU93/INXv9QbtRiDmjsG0ByoF4K5nTxFn8u9CmTp/OctgRclA2o5iFZm5bAExbMJmw X-Received: by 2002:a17:90b:3644:b0:263:f630:228f with SMTP id nh4-20020a17090b364400b00263f630228fmr2503089pjb.23.1695210984818; Wed, 20 Sep 2023 04:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695210984; cv=none; d=google.com; s=arc-20160816; b=TgQLPrCAiQNvDmPvK8Ph2YNyYQTI4d7xJOofCPzBv8FkKw9Ci3mOdnSoLjyoti6afL EyvMKkI+O3+2FeYlaFCgaXc8isat6iCxxmQRMO+rdJr9/KasZjwBtqbfj1d1P3SCTONx T0FlfRkYG7bB8G+WAom8oqI9dVqie+TVIVeLrEu0ystmvRac+Y31B5v7HOYUQuyOIk2V 1+5cuFt7c3AA3pj4fxvA1CtNN2ITS1A6WAqGnlWeZmI5ps5cXuB1K2viwhjjsum1KmgH /ZFK9sTy3Sm5n5P2ZnIn6B/uktbniZAuXj0Tc740OWe7Og9CSJVGBLLmboaE+QIzU0pI tvEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=+vT4SUdk/noi3Bfyw6aEN5lsHOerNwZ9sR4iLopbKcY=; fh=aaBeJ2HmOA2jsIuDSW9KhQ1qhFXkvQ7iPyaAqDoN6Vc=; b=bgeY8i72S5ZtcAG3m19KEVY6LFVE2GNVJqUW0FdFVzgLBNySmBLsXlilbGByHCq1m1 goVgk/kNWAv3d6nT6VnfIzpnc7qlCV2lPx3Nl3RwJ5m3jFo6PGADP5atTk6Vp2FJlxkJ 8Z+uP9Lzptp/YybUUj9KxRk9zN9fc5VbuyBI054nark0b+lZWZJMZeL8GO9UgEWUgnEN qjODG6fRWPnPtRe4MrdSf9VydM82COWsQXDEkX9yDE25sfdBrg+Ir+2+gPs5ncuWqAqA SyC/mOE/PvxchN27iIcSOydT8Qg9xfQUvD7IGXueGbBACsRRDj0bjfFNwVjitUPa1gPt A0IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fuJXOOFq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id md9-20020a17090b23c900b00256d7cc5b67si933236pjb.133.2023.09.20.04.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 04:56:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fuJXOOFq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 59C3D80BCB97; Wed, 20 Sep 2023 03:51:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234307AbjITKvR (ORCPT + 99 others); Wed, 20 Sep 2023 06:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbjITKvL (ORCPT ); Wed, 20 Sep 2023 06:51:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D2F0E6; Wed, 20 Sep 2023 03:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695207065; x=1726743065; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=Xf+UZEfn7rC+Qte0CL3CXZpBR9LRbgEa0lssvdc8chs=; b=fuJXOOFqYHczGBzY9QQoUECs7ImY2NF2BZwuL40cvhnzT4ImW3c4xQ13 I3yDXwRKLGM/bxrrrwYth0ug0K5gXxIstNQafU2u9zPoWkt7XIvOznnDx SzqcbKqLABX5XReryrzIhPM6kWU6ZRAIs7t8AV6JYnQNxkXfabSRnQWFI fjAXoxk4sBTae9syyJfzCO59YzupTT7VG2Le8q/YdrOMJ4INjTDBgz9K2 BYqhumnXRDptg+yX50R+OB7EWb64bDGpO6Elq5lcT4W237BOjsfIWqdDQ PYjT2dZQxWY6Lg+kcoObJhVquG8RHz4+guUaZZ45+q0DgYvzHXkKu5WUB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="466501487" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="466501487" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2023 03:51:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="746596854" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="746596854" Received: from swegrzyn-mobl.ger.corp.intel.com ([10.252.52.91]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2023 03:51:01 -0700 Date: Wed, 20 Sep 2023 13:50:58 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Fernando Eckhardt Valle cc: Hans de Goede , Mark Pearson , corbet@lwn.net, hmh@hmh.eng.br, markgross@kernel.org, linux-doc@vger.kernel.org, LKML , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH v3] platform/x86: thinkpad_acpi: sysfs interface to auxmac In-Reply-To: <20230919201136.63736-1-fevalle@ipt.br> Message-ID: <965b4ab5-3526-c7c-58ab-2252734e3ad6@linux.intel.com> References: <20230919201136.63736-1-fevalle@ipt.br> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 20 Sep 2023 03:51:44 -0700 (PDT) On Tue, 19 Sep 2023, Fernando Eckhardt Valle wrote: > Newer Thinkpads have a feature called MAC Address Pass-through. > This patch provides a sysfs interface that userspace can use > to get this auxiliary mac address. > > Signed-off-by: Fernando Eckhardt Valle Thanks for the update, in general this looks much better already. A few further comments below. > --- > Changes in v3: > - Added null terminator to auxmac string when copying auxiliary > mac address value. > Changes in v2: > - Added documentation > - All handling of the auxmac value is done in the _init function. > --- > .../admin-guide/laptops/thinkpad-acpi.rst | 20 +++++ > drivers/platform/x86/thinkpad_acpi.c | 81 +++++++++++++++++++ > 2 files changed, 101 insertions(+) > > diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst > index e27a1c3f6..98d304010 100644 > --- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst > +++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst > @@ -53,6 +53,7 @@ detailed description): > - Lap mode sensor > - Setting keyboard language > - WWAN Antenna type > + - Auxmac > > A compatibility table by model and feature is maintained on the web > site, http://ibm-acpi.sf.net/. I appreciate any success or failure > @@ -1511,6 +1512,25 @@ Currently 2 antenna types are supported as mentioned below: > The property is read-only. If the platform doesn't have support the sysfs > class is not created. > > +Auxmac > +------ > + > +sysfs: auxmac > + > +Some newer Thinkpads have a feature called MAC Address Pass-through. This > +feature is implemented by the system firmware to provide a system unique MAC, > +that can override a dock or USB ethernet dongle MAC, when connected to a > +network. This property enables user-space to easily determine the MAC address > +if the feature is enabled. > + > +The values of this auxiliary MAC are: > + > + cat /sys/devices/platform/thinkpad_acpi/auxmac > + > +If the feature is disabled, the value will be 'disabled'. > + > +This property is read-only. > + > Adaptive keyboard > ----------------- > > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c > index d70c89d32..ccb4969ac 100644 > --- a/drivers/platform/x86/thinkpad_acpi.c > +++ b/drivers/platform/x86/thinkpad_acpi.c > @@ -10785,6 +10785,82 @@ static struct ibm_struct dprc_driver_data = { > .name = "dprc", > }; > > +/* > + * Auxmac > + * > + * This auxiliary mac address is enabled in the bios through the > + * MAC Address Pass-through feature. In most cases, there are three > + * possibilities: Internal Mac, Second Mac, and disabled. > + * > + */ > + > +#define AUXMAC_LEN 12 > +#define AUXMAC_START 9 > +#define AUXMAC_STRLEN 22 > +#define AUXMAC_BEGIN_MARKER 8 > +#define AUXMAC_END_MARKER 21 > +static char auxmac[AUXMAC_LEN + 1]; Add a newline between the defines and the declaration. > + > +static int auxmac_init(struct ibm_init_struct *iibm) > +{ > + acpi_status status; > + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > + union acpi_object *obj; > + > + status = acpi_evaluate_object(NULL, "\\MACA", NULL, &buffer); > + > + if (ACPI_FAILURE(status)) > + return -ENODEV; > + > + obj = (union acpi_object *)buffer.pointer; Assigment from void * does not need explicit casting. > + > + if (obj->type != ACPI_TYPE_STRING || obj->string.length != AUXMAC_STRLEN) { > + pr_info("Invalid buffer for MAC address pass-through.\n"); > + goto auxmacinvalid; > + } > + > + if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' || > + obj->string.pointer[AUXMAC_END_MARKER] != '#') { > + pr_info("Invalid header for MAC address pass-through.\n"); > + goto auxmacinvalid; > + } > + > + if (strncmp(obj->string.pointer + AUXMAC_START, "XXXXXXXXXXXX", AUXMAC_LEN) != 0) { > + memcpy(auxmac, obj->string.pointer + AUXMAC_START, AUXMAC_LEN); > + auxmac[AUXMAC_LEN] = '\0'; > + } else > + strcpy(auxmac, "disabled"); strcpy() is deprecated, please use strscpy(). https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy Btw, the usual coding style requires braces to be balanced so the else should have braces on both sides if either side requires them. > + kfree(obj); > + return 0; > + > +auxmacinvalid: > + kfree(obj); > + strcpy(auxmac, "unavailable"); strscpy(). Can't you do this strscpy() before you goto here? Then you can share the return path with the normal return path since only kfree() remains here. -- i. > + return 0; > +} > + > +static struct ibm_struct auxmac_data = { > + .name = "auxmac", > +}; > + > +static ssize_t auxmac_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + return sysfs_emit(buf, "%s\n", auxmac); > +} > +static DEVICE_ATTR_RO(auxmac); > + > +static struct attribute *auxmac_attributes[] = { > + &dev_attr_auxmac.attr, > + NULL > +}; > + > +static const struct attribute_group auxmac_attr_group = { > + .attrs = auxmac_attributes, > +}; > + > /* --------------------------------------------------------------------- */ > > static struct attribute *tpacpi_driver_attributes[] = { > @@ -10843,6 +10919,7 @@ static const struct attribute_group *tpacpi_groups[] = { > &proxsensor_attr_group, > &kbdlang_attr_group, > &dprc_attr_group, > + &auxmac_attr_group, > NULL, > }; > > @@ -11414,6 +11491,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { > .init = tpacpi_dprc_init, > .data = &dprc_driver_data, > }, > + { > + .init = auxmac_init, > + .data = &auxmac_data, > + }, > }; > > static int __init set_ibm_param(const char *val, const struct kernel_param *kp) >