Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1695330ybh; Tue, 14 Jul 2020 05:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw41vN9Ciom+1ekiTy/HOoqdrZD5h26QJSxFwCXhIXzFVIq+2ORldSZe3YLUwX/AWZzFMTM X-Received: by 2002:a17:906:444e:: with SMTP id i14mr4006907ejp.418.1594728242249; Tue, 14 Jul 2020 05:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728242; cv=none; d=google.com; s=arc-20160816; b=qEQvd9TBncvslm4rRFNoYLGnbGCNBEnPw2Yv8/mFxMNfwYQQOyAFZOB0d4I8hbxjjA y+OAlT+1/yuxk04azIKBBDx6RLIV/hcP1GxL6hPOHVeTx+tZ+e4n8oYZRHnTEF8sichC 1GLehsZTMDqCVB9NpoNpkAJudX4ScN7Pg8ul8fhRNL9tQAXI94o8fcjDry29GzBV6sg0 Zz8faFXYb2oQsmPtnFoVOxjk/5xAibBq/Krtvm4BoYEA54ep6suO8KRkvTePUsfoUXV8 plXmE9VDoOkTHJFcsJNAuqHzdKbE/oCerZ0rAC0h9l3z//f5HYGQ/G7tmHxQhlP23Cfs EHDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KSJ2NY95II0KuGFGz0hrKu1XQ3EQBEFHS7nrGKZAWyE=; b=XdtVPoRfQAXIqNAG/GO5WMPVot0Y77GfidCbylP91RWiR3NiIUmQDLqPrYfUB9UZTd /ZObzD51sDUCi7Ub+VsZ52yea5XlsZWscnnp35D7t/fbukAoPByosgIA43o3rMiOOr1u sdZeJRg316zpr5n1uSx6JRo5S26h4Fm2W959UIM3meAISxP+wfhd8kZ+88H/qy6UdoZQ D1VuIx8YsTN0n4MRqLTncVxDFqhq5SDneDiGE63O10j433j+p5dyLN/9we0qrs4/VyL+ YYjP/+I8oDT0OmCdXUuieq+EsrcxjkpFDQ3xXM7JagCnh7KDfF4CF+ki2SMVWCSGquTj V9Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id of23si10644792ejb.414.2020.07.14.05.03.39; Tue, 14 Jul 2020 05:04:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbgGNMCU (ORCPT + 99 others); Tue, 14 Jul 2020 08:02:20 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52608 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728116AbgGNMCS (ORCPT ); Tue, 14 Jul 2020 08:02:18 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vadimp@mellanox.com) with SMTP; 14 Jul 2020 15:02:12 +0300 Received: from r-build-lowlevel.mtr.labs.mlnx. (r-build-lowlevel.mtr.labs.mlnx [10.209.0.190]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 06EC25di004353; Tue, 14 Jul 2020 15:02:12 +0300 From: Vadim Pasternak To: andy@infradead.org, dvhart@infradead.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Vadim Pasternak Subject: [PATCH platform-next v2 05/11] platform/mellanox: mlxreg-hotplug: Add environmental data to uevent Date: Tue, 14 Jul 2020 15:01:57 +0300 Message-Id: <20200714120203.10352-6-vadimp@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200714120203.10352-1-vadimp@mellanox.com> References: <20200714120203.10352-1-vadimp@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Send "udev" event with environmental data in order to allow handling "ENV{}" variables in "udev" rules. Signed-off-by: Vadim Pasternak --- v1->v2: Comments pointed out by Andy: - Add string_upper(), string_lower() helpers. Use string_upper() for label conversion. - Simplify code for event string construction. --- drivers/platform/mellanox/mlxreg-hotplug.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c index d9863e7fd491..b013445147dd 100644 --- a/drivers/platform/mellanox/mlxreg-hotplug.c +++ b/drivers/platform/mellanox/mlxreg-hotplug.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,23 @@ struct mlxreg_hotplug_priv_data { u8 not_asserted; }; +/* Environment variables array for udev. */ +static char *mlxreg_hotplug_udev_envp[] = { NULL, NULL }; + +static int +mlxreg_hotplug_udev_event_send(struct kobject *kobj, + struct mlxreg_core_data *data, bool action) +{ + char event_str[MLXREG_CORE_LABEL_MAX_SIZE + 2]; + char label[MLXREG_CORE_LABEL_MAX_SIZE] = { 0 }; + + mlxreg_hotplug_udev_envp[0] = event_str; + string_upper(label, data->label); + snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action); + + return kobject_uevent_env(kobj, KOBJ_CHANGE, mlxreg_hotplug_udev_envp); +} + static int mlxreg_hotplug_device_create(struct mlxreg_hotplug_priv_data *priv, struct mlxreg_core_data *data) { @@ -78,7 +96,7 @@ static int mlxreg_hotplug_device_create(struct mlxreg_hotplug_priv_data *priv, struct i2c_client *client; /* Notify user by sending hwmon uevent. */ - kobject_uevent(&priv->hwmon->kobj, KOBJ_CHANGE); + mlxreg_hotplug_udev_event_send(&priv->hwmon->kobj, data, true); /* * Return if adapter number is negative. It could be in case hotplug @@ -118,7 +136,7 @@ mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_priv_data *priv, struct mlxreg_core_data *data) { /* Notify user by sending hwmon uevent. */ - kobject_uevent(&priv->hwmon->kobj, KOBJ_CHANGE); + mlxreg_hotplug_udev_event_send(&priv->hwmon->kobj, data, false); if (data->hpdev.client) { i2c_unregister_device(data->hpdev.client); -- 2.11.0