Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp41340imm; Mon, 1 Oct 2018 06:24:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV63iO0IOzk2mxQz2YFFOxUnrr+Twr82ryLPwiNIKayl7LfYzNrNzv9++jgxNaYMXKWL84yZK X-Received: by 2002:a63:3e06:: with SMTP id l6-v6mr10095114pga.96.1538400298245; Mon, 01 Oct 2018 06:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538400298; cv=none; d=google.com; s=arc-20160816; b=sbnqMv4zxm7+GOTHYFZeGvg2aAmV6rOCqXVAX43O3VMhYSJJRL69yAfIrXrtW3/bxk 2wxGxznUUtrtwTGrfPidM3j3acaOcl3ay0SonKfZhKo/4sqrgUDfEPuT/GAu2Oa6EDhn lp8fdcyttS3qy2GzDqPe/mHrQR9Ja/gdSC/HPfaIoRk5aWJ4m+8L+s8Ej8vsb63u/g2r /zom8dE7ivM+Jvb/USeet8ET057DG6sGbr5pyMVUEfQzBdvk7DTGehKzdk7GBfduZPoW gbaKj6/vBUZlAhFZQfY47s4tLUqajWDVnNUmNAn5L9xk7zfdEK/Rjkp/1Ev9OUF5neH9 zmwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=XwJXc+nolbUqwVri59xFpdYSs5Io+ZqzajXVi2uMvEI=; b=w4tJi56Zcfy+cLACslqLKga4026ZH+StukfOv4V8pkiiDH7DBzgNnVgR1ajDJSG8Br bHbHeLBaTI+yHOIg14IkbHFCxBevxB25ZVqZhLopdcBEtgUQlVB2/smdvALNo5xNgiFW TtfxCIjmSWLxV0rhQ6OxP5vHX0D0v3x1/ephbcOQCNE/teK4byRZsSVNiKHPVnrKPPdV dYQVpXaTKxs/j94ga/1w/BvXBdU9XBv0U1MSM+yPHrLXld/858bY7CaH8VK9N1IxQgpD KajQmMQotqCZWlQdMDtrd+4+sQk/hahZ3Oz9rpfjU1xIStjKxQ6Ji+C7B16WUFFO/Mic 6+Ww== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 43-v6si13432347plb.444.2018.10.01.06.24.41; Mon, 01 Oct 2018 06:24:58 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729367AbeJAUC1 (ORCPT + 99 others); Mon, 1 Oct 2018 16:02:27 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:47524 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729182AbeJAUC0 (ORCPT ); Mon, 1 Oct 2018 16:02:26 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w91DJIvw019119; Mon, 1 Oct 2018 15:24:13 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2mu1bjmav9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 01 Oct 2018 15:24:13 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 71E6431; Mon, 1 Oct 2018 13:24:12 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 457F4465E; Mon, 1 Oct 2018 13:24:12 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 1 Oct 2018 15:24:11 +0200 From: Fabrice Gasnier To: , CC: , , , , , , , , , , , Subject: [PATCH v2 2/2] pwm: send a uevent on the pwmchip device upon channel sysfs (un)export Date: Mon, 1 Oct 2018 15:23:57 +0200 Message-ID: <1538400237-28766-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538400237-28766-1-git-send-email-fabrice.gasnier@st.com> References: <1538400237-28766-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-01_08:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch sends a uevent (KOBJ_CHANGE) on the pwmchipN device, everytime a pwmX channel has been exported/unexported via sysfs. This allows udev to implement rules on such events, like: SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\ chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\ chown -R root:gpio /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\ '" This is a replacement patch for commit 7e5d1fd75c3d ("pwm: Set class for exported channels in sysfs"), see [1]. basic testing: $ udevadm monitor --environment & $ echo 0 > /sys/class/pwm/pwmchip0/export KERNEL[197.321736] change /devices/.../pwm/pwmchip0 (pwm) ACTION=change DEVPATH=/devices/.../pwm/pwmchip0 EXPORT=pwm0 SEQNUM=2045 SUBSYSTEM=pwm [1] https://lkml.org/lkml/2018/9/25/713 Signed-off-by: Fabrice Gasnier Tested-by: Gottfried Haider --- drivers/pwm/sysfs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 4726d43..ceb233d 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -249,6 +249,7 @@ static void pwm_export_release(struct device *child) static int pwm_export_child(struct device *parent, struct pwm_device *pwm) { struct pwm_export *export; + char *pwm_prop[2]; int ret; if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags)) @@ -276,6 +277,10 @@ static int pwm_export_child(struct device *parent, struct pwm_device *pwm) export = NULL; return ret; } + pwm_prop[0] = kasprintf(GFP_KERNEL, "EXPORT=pwm%u", pwm->hwpwm); + pwm_prop[1] = NULL; + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); + kfree(pwm_prop[0]); return 0; } @@ -288,6 +293,7 @@ static int pwm_unexport_match(struct device *child, void *data) static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm) { struct device *child; + char *pwm_prop[2]; if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags)) return -ENODEV; @@ -296,6 +302,11 @@ static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm) if (!child) return -ENODEV; + pwm_prop[0] = kasprintf(GFP_KERNEL, "UNEXPORT=pwm%u", pwm->hwpwm); + pwm_prop[1] = NULL; + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); + kfree(pwm_prop[0]); + /* for device_find_child() */ put_device(child); device_unregister(child); -- 1.9.1