Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACA47C47257 for ; Mon, 4 May 2020 20:30:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C5E2205ED for ; Mon, 4 May 2020 20:30:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QNsTHDRZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728036AbgEDUaA (ORCPT ); Mon, 4 May 2020 16:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727890AbgEDU35 (ORCPT ); Mon, 4 May 2020 16:29:57 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADB6C061A10 for ; Mon, 4 May 2020 13:29:56 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id a32so468207pje.5 for ; Mon, 04 May 2020 13:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3jc0TOyQ4war+DAm2+lh4uAs3ApKGMVi9why4UvGExE=; b=QNsTHDRZoZuDPWYQs4Csq+6FgUrP8w3uyMqQAR+1uJZZGAxtjqBK6vIQLXiLro9EUM rZiKT7UuJeIhn7v8tm363KM+VROs4JMrqn+S7N7HytoMEK+V/od5eq1OdNDeXkskr4S1 0ilRHOmV42klq2IeepjH+ryE1UU5IjBInAFLI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3jc0TOyQ4war+DAm2+lh4uAs3ApKGMVi9why4UvGExE=; b=LHZSe0UZBU3aj1k3Lq7y7e4ETcSt5Oieno/8cEMF4gmo+ey8b8DBE7hwUmQMXR5EoS dEr5a+Jsa7RvUPMwSGKjEsh0vYsj790JPI0//HooqXjxiL7Wc1b6b/bS/d8MwVb1lfgq jX240xIvVnmNn1fXTD+ZJi1ar2lExEhXYDiM9dwrg1nkWWmdoYUtWjDq7cjlnS98g8Ih l5woC/WKGG8KpsQ9wY6fNC3Ro/h02mwXl/ujPbk1zD2l3ijQh5DBoKD+VljU29wgbdq5 MannN0Up1BCkqbYTJF2tbT919zgCbLwZzJtxCHYQo2317AAYUl86E4gItReEhouYhI7b 8ArA== X-Gm-Message-State: AGi0PuZc6GfOMxYT1dWhKe1k2QdnmcPXjG5AnWAdasz1CxenkcoMQL7n dimPhs8E+70//jlIE8I/5qwA/8Go16/B5Q== X-Google-Smtp-Source: APiQypKaJu64Aen3AruMc8A3xz6cDGP1Ljua3iefkQJP7oxlKh9bFxhPzW0F/NDlcNiJYNL4gl8S4g== X-Received: by 2002:a17:902:a40b:: with SMTP id p11mr1019115plq.304.1588624196117; Mon, 04 May 2020 13:29:56 -0700 (PDT) Received: from mathewk1.lan ([161.97.192.125]) by smtp.gmail.com with ESMTPSA id z23sm9511737pfr.136.2020.05.04.13.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 13:29:55 -0700 (PDT) From: Mathew King To: linux-kernel@vger.kernel.org Cc: Mathew King , Sebastian Reichel , linux-pm@vger.kernel.org Subject: [PATCH v2 4/4] power_supply: Add power supply type property to uevent env Date: Mon, 4 May 2020 14:29:30 -0600 Message-Id: <20200504202930.228453-5-mathewk@chromium.org> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog In-Reply-To: <20200504202930.228453-1-mathewk@chromium.org> References: <20200504202930.228453-1-mathewk@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add POWER_SUPPLY_TYPE to the uevent env for power supply. Type is a property of all power supplies and there is a sysfs entry for it but it is not included in the properties array of the power supply so explicitly add it to the udev env. Signed-off-by: Mathew King --- v2: - Fixup with patches in series --- drivers/power/supply/power_supply_sysfs.c | 61 ++++++++++++++--------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 8f90daff0003..d856aed8cb41 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -410,6 +410,37 @@ void power_supply_init_attrs(struct device_type *dev_type) } } +static int add_prop_uevent(struct device *dev, struct kobj_uevent_env *env, + enum power_supply_property prop, char *prop_buf) +{ + int ret = 0; + struct power_supply_attr *pwr_attr; + struct device_attribute *dev_attr; + char *line; + + pwr_attr = &power_supply_attrs[prop]; + dev_attr = &pwr_attr->dev_attr; + + ret = power_supply_show_property(dev, dev_attr, prop_buf); + if (ret == -ENODEV || ret == -ENODATA) { + /* + * When a battery is absent, we expect -ENODEV. Don't abort; + * send the uevent with at least the the PRESENT=0 property + */ + return 0; + } + + if (ret < 0) + return ret; + + line = strchr(prop_buf, '\n'); + if (line) + *line = 0; + + return add_uevent_var(env, "POWER_SUPPLY_%s=%s", + pwr_attr->prop_name, prop_buf); +} + int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env) { struct power_supply *psy = dev_get_drvdata(dev); @@ -429,31 +460,13 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env) if (!prop_buf) return -ENOMEM; - for (j = 0; j < psy->desc->num_properties; j++) { - struct power_supply_attr *pwr_attr; - struct device_attribute *dev_attr; - char *line; - - pwr_attr = &power_supply_attrs[psy->desc->properties[j]]; - dev_attr = &pwr_attr->dev_attr; - - ret = power_supply_show_property(dev, dev_attr, prop_buf); - if (ret == -ENODEV || ret == -ENODATA) { - /* When a battery is absent, we expect -ENODEV. Don't abort; - send the uevent with at least the the PRESENT=0 property */ - ret = 0; - continue; - } - - if (ret < 0) - goto out; - - line = strchr(prop_buf, '\n'); - if (line) - *line = 0; + ret = add_prop_uevent(dev, env, POWER_SUPPLY_PROP_TYPE, prop_buf); + if (ret) + goto out; - ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s", - pwr_attr->prop_name, prop_buf); + for (j = 0; j < psy->desc->num_properties; j++) { + ret = add_prop_uevent(dev, env, psy->desc->properties[j], + prop_buf); if (ret) goto out; } -- 2.26.2.526.g744177e7f7-goog