Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3377112imm; Tue, 29 May 2018 06:18:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrvDc0Mu2LuDRT3CHC/3UB+EIHf9TwK9BKJO9qIe0l5SI5buiyEaZzK7XfNen7mtlitR6zZ X-Received: by 2002:a63:3c4c:: with SMTP id i12-v6mr13855435pgn.309.1527599883507; Tue, 29 May 2018 06:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527599883; cv=none; d=google.com; s=arc-20160816; b=qE0m7kRWiXjpJop2PRKvbEFx7boSRrKmzEZFKPigNx+10rJJPSwDJpKmQ1JEnuwHUc zoC3B62Uao5r9H6DF+NK8LLqXmJ+7hPs+1fYHoDyfuyi5kivyKTyELeVvt8Cw6/vLolg 4VDHtpMXEbwuHtPpsFgj56xIK8wyIKeEwBk1gXkLJTVDjwhXKBnLB2iedplrEIvJ993Z xXl20jZoomNTvXBtwZMkvcn5LxnGgPqyw5qPO+U7yF7pFSQzA0rBUVJdtIpA2xy1zNbs 5KRXvUcUDqp4+oV09lV9BLtVzW/1bNAEpsVX+2200s6P3WCm+QyRIe+NRT+35bo6ZmJ9 9lMA== 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:dkim-signature:arc-authentication-results; bh=TAQowHuS+6HysH11Vt2hI/bBr5VGTjhm7B11vPQuU6Q=; b=as0QA8Ekr6c/XKSFoN/JZlqg2vOHCmf3zPRiI/9PEwv2viRpmg1XMBBgaQG5EMuZv7 H2/Vk3pnL4tSWagKCBL/GaCsBLqEtHhezYjinDHs5LDu1ouxLc9in2QUuNl0tc5Cpoav F+narlhKlat7HfaV0NM8IYg5+0lzvG6/OPhTXNbDPJgdsxzwwHeIyfeYnWwDeUUvOWV7 vXAib1wd5yP3qlHh/lAcZf/CxcKLobL+5svcoTvXw221W6Thyksf6kUlfivA3/6vESf7 ZM70665tl7m4nyb9XxHxbPFhllK3JQWsxWZWW5vFQWkn6Fh9559IICFF9gUEGIqn8Gec aN/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sW8y3pno; 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 q19-v6si7765829pls.139.2018.05.29.06.17.49; Tue, 29 May 2018 06:18:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sW8y3pno; 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 S934521AbeE2NPY (ORCPT + 99 others); Tue, 29 May 2018 09:15:24 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37342 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934516AbeE2NKo (ORCPT ); Tue, 29 May 2018 09:10:44 -0400 Received: by mail-wm0-f67.google.com with SMTP id l1-v6so40512954wmb.2; Tue, 29 May 2018 06:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TAQowHuS+6HysH11Vt2hI/bBr5VGTjhm7B11vPQuU6Q=; b=sW8y3pnoE9NUYOJO0KvM2IxxQLBtW+0I6vNWiPP1Ngq7i8OnJjhdJw7YTgXt41FVnl UrZ9QUJJx8AcdasVOL2mg8pdPK9mbc0Un+/b247j7RMMx5+myCt2499fxgNps1OzTTmv b/R8V0iR17eOylS/qDEYCnDEt8TZX5Og2v2XOHyDJJ+9Z0SjOCTOeW9aX30fR3BbHblE zD4/2BzAgoyMFPEG1MTThnNGE4QG/id9Aj3xF1b/cdYTEIf3JvX+uDIWX75KrO7Jnq2w U0r1QBfjEfE5v4Gx5yaaF9nq84dTgyhWAupElglL6Gw743LXzNbS/XpqrLcNunK4xdzS l+zQ== 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; bh=TAQowHuS+6HysH11Vt2hI/bBr5VGTjhm7B11vPQuU6Q=; b=WeBnPfCaLm4NOEa+GrK1+pn84laDuNI5XKDUaqK+Y/5hRzACOrDvdr/I7hNn9WJmUe 05nMLFTDI3L5g5ZlKZbdJupl/s8dYFJ0YRRxlKp47lHGUrSHv5J2ebj3u5YiAVGBIUQp j1xpY1bTwrR5fdzc2iDV1+ZK1F6IFcPlE/lwRq90cTLa636JUR/tyGwnqdsYgLjOMD8J LmZfjOXhJrw/26InFJs3ZJKffjIMyxxUnL3wfXq7ci+UKcy/g/pCwq09yjmpBmPiWQkX VZ8Q/D84UBVN+hhIYwO1YjyLzM8Kf/FpYAtfWJ/YMB8pvgbm0XtE1rV0z0o6J1F9jmry W5+Q== X-Gm-Message-State: ALKqPwe8bM4zGGl201OdKwXLf0TnyPm1D02nmfJ/crWGFP2Kul56xtP3 /pbkYSQ2lBcsgHjal8dnj33XFglK X-Received: by 2002:a50:c34e:: with SMTP id q14-v6mr14553519edb.178.1527599442965; Tue, 29 May 2018 06:10:42 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id c15-v6sm17443220edr.78.2018.05.29.06.10.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 06:10:41 -0700 (PDT) From: Ricardo Ribalda Delgado To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Ricardo Ribalda Delgado , Rob Herring , Johan Hovold , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH 07/19] serdev: Allows dynamic creation of devices via sysfs Date: Tue, 29 May 2018 15:10:02 +0200 Message-Id: <20180529131014.18641-8-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180529131014.18641-1-ricardo.ribalda@gmail.com> References: <20180529131014.18641-1-ricardo.ribalda@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow creating and deleting devices via sysfs. Devices created will be matched to serdev drivers via modalias (the string provided by the user) and deleted via their name. Eg: # Create device root@qt5022:~# echo ttydev > /sys/bus/serial/devices/serial0/new_device # Delete device root@qt5022:~# echo serial0-0 > /sys/bus/serial/devices/serial0/delete_device Cc: Rob Herring Cc: Johan Hovold Cc: Greg Kroah-Hartman Cc: Jiri Slaby Signed-off-by: Ricardo Ribalda Delgado --- drivers/tty/serdev/core.c | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 2c79f47fc0db..e695fa649a6d 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -75,7 +75,67 @@ static void serdev_ctrl_release(struct device *dev) kfree(ctrl); } +static ssize_t +new_device_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct serdev_controller *ctrl = to_serdev_controller(dev); + struct serdev_device *serdev; + int err; + char *nline; + + serdev = serdev_device_alloc(ctrl); + if (!serdev) + return -ENOMEM; + + nline = strchr(buf, '\n'); + if (nline) + *nline = '\0'; + + strncpy(serdev->modalias, buf, SERDEV_NAME_SIZE); + + err = serdev_device_add(serdev); + if (err) { + serdev_device_put(serdev); + return err; + } + + return count; +} +static DEVICE_ATTR_WO(new_device); + +static ssize_t +delete_device_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct serdev_controller *ctrl = to_serdev_controller(dev); + struct serdev_device *serdev = ctrl->serdev; + char *nline; + + nline = strchr(buf, '\n'); + if (nline) + *nline = '\0'; + + if (!ctrl->serdev || + strncmp(dev_name(&serdev->dev), buf, SERDEV_NAME_SIZE)) + return -ENODEV; + + serdev_device_remove(serdev); + + return count; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + delete_device_store); + +static struct attribute *serdev_ctrl_attrs[] = { + &dev_attr_new_device.attr, + &dev_attr_delete_device.attr, + NULL +}; +ATTRIBUTE_GROUPS(serdev_ctrl); + static const struct device_type serdev_ctrl_type = { + .groups = serdev_ctrl_groups, .release = serdev_ctrl_release, }; -- 2.17.0