From patchwork Tue Nov 22 10:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 24255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2118945wrr; Tue, 22 Nov 2022 02:24:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf5L/KGWo0YsM6OcQxHXwRN1DtW7SzN8LqHYqMq8X5NE5GLL17Bxhl1yhxkIf7EhQeFDQrhY X-Received: by 2002:a17:906:d20a:b0:7a9:8d8e:c3df with SMTP id w10-20020a170906d20a00b007a98d8ec3dfmr3508236ejz.519.1669112699818; Tue, 22 Nov 2022 02:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669112699; cv=none; d=google.com; s=arc-20160816; b=FZeMEq9ry0A9djMlcQwVz3M9WFkm1hCLcVEYjyIR8pjv4QxgeIzS8v7fc3V0l1YuXf CiLTeDsvq/3MvDnW3idirlSHOWe4sVcz+YGfUti+H4oHE2HM1y/jHA0NBkXb3SLPMILi 4KVK81PQe6UnPICeWF7zQgQOMlEoJlR2TwIUyeBczTCzYgQYuDTh9kHy/dz5Swka4m3N kinp15Uf22g8C5siyARHoX9D8Rwflf+ci6/NeequOqwGqu9gy6Mva2Q0MZ80pAJ2TeGN 6ae40CSV0qJA+nrz0KpKH/sHZmtHUMMS5WnH9Z57qOCyVN5v/98r3QLfNYaOVx5km+pT 7XrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j23hZnphv0jcgZfiOY9qWXNDpMCFFj9PRM3bEUKGmc4=; b=aetokoQ/XUnogyHKQgmCfHpbq4ZyZbR1ES6d9mCOrn97+Eb810EHlwhcpWOAAignCy kZlfo2BvQklnZpKjIy1gHBHVRdZKGedpZ1D6crjyR8Si1hZ5byUadpDdVG1+QPoB0miF llLmNmBlXFr6Ur39wFtTJ2R+lQPlaAjVKTlK1DhPBZomgoF5mf05x1DLo38jOIQqtX0n zExMWQi/sFNwk26+HxKQARNuy+YWfqzoaDLhSzz+XYTaGje1WOeBPUaIZMXTiuhWvyzL cNYSIs+rLi+dvCyvzQA+cEZGsdbe6yRVrTesexPZOwHfDvzol9eX8R/0pFVPH4lVcahd IPOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=fDNYsQ3j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du16-20020a17090772d000b0078200e81b92si13277124ejc.758.2022.11.22.02.24.35; Tue, 22 Nov 2022 02:24:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=fDNYsQ3j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233640AbiKVKXx (ORCPT + 99 others); Tue, 22 Nov 2022 05:23:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbiKVKWL (ORCPT ); Tue, 22 Nov 2022 05:22:11 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395F111818 for ; Tue, 22 Nov 2022 02:21:54 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id o30so10380017wms.2 for ; Tue, 22 Nov 2022 02:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j23hZnphv0jcgZfiOY9qWXNDpMCFFj9PRM3bEUKGmc4=; b=fDNYsQ3j2gLDbZskMdzxyTjl8yIPfTyD01yYPRdSjW+X6zPNqK3ztySziZezPu419E suCJQuvywgERUuFjcEnHi4Z1QQWUyfFO4bjGUFByDMTU2ML1XaBgAmunf8cy0bjbUiW6 daoPwkNXiRew7YerkscSIQfCA1vTfCA/zQEJYA+Gy88c/te+ILvMNZbT6x+k+h8ZXa58 AhXsEKNQkEnyM1McFXynLRGACGVnivDCet0jtDLXhYTpNVJlBqHoZ63GGUSki5MbqFCA mruZWz6KtrRz2f/+SjzX2D9ZkEppU8HB1XaTcih4ryJpVJ1rEiWyU2v/OrqDDX3QhTzV PjKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j23hZnphv0jcgZfiOY9qWXNDpMCFFj9PRM3bEUKGmc4=; b=YcWTIjHau2Mjo9oB97NqOOTh/2B0GRXDlUThKzLKv/4yuZK7wW+9i6IQ9Lbpt3X1R1 osCEEx8biL/APMawGHHzg4LJgmZeNGtf9QUamPiFo0V43zOfpW1GuUrMvWo8cWHq4l/M /Tum0zNajEGc+2xAtrx8ryq+7u8H8LHgzaw4HxBcbdr2JQqofRbZQX83EGuv9Ux1IS6a gfSEvkiFsz6aw4EBX1rCLvlEE+W3wgNbwFEnh5gpVYDDpMVDgxP8IeeNda9z1JYaLMju Q3fq4WWzWZajmDN1FEdsGuK+F7n4M5DEfBAK2q5ukuYuocehpY+DPCVsPgdeRSMGh7WI ryOQ== X-Gm-Message-State: ANoB5plNkW20CLauyUooJewrC1uBSUyDapxh02YpgVxGFNfFNa46+Bn/ 89bLpePT817KK8VZ3UOZtIB7eQ== X-Received: by 2002:a7b:cb98:0:b0:3cf:9a12:e645 with SMTP id m24-20020a7bcb98000000b003cf9a12e645mr8714322wmi.59.1669112512755; Tue, 22 Nov 2022 02:21:52 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:e011:9e81:66f1:3415]) by smtp.gmail.com with ESMTPSA id o3-20020a5d4083000000b002366e8eee11sm13432873wrp.101.2022.11.22.02.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 02:21:52 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , Srinivas Kandagatla , Vinod Koul , Alex Elder , =?utf-8?q?Ilp?= =?utf-8?q?o_J=C3=A4rvinen?= Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 12/15] tty: serial: provide devm_uart_add_one_port() Date: Tue, 22 Nov 2022 11:21:22 +0100 Message-Id: <20221122102125.142075-13-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221122102125.142075-1-brgl@bgdev.pl> References: <20221122102125.142075-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750191518353622790?= X-GMAIL-MSGID: =?utf-8?q?1750191518353622790?= From: Bartosz Golaszewski Provide a devres variant of uart_add_one_port() that removes the managed port at device detach. Signed-off-by: Bartosz Golaszewski --- .../driver-api/driver-model/devres.rst | 3 ++ drivers/tty/serial/serial_core.c | 36 +++++++++++++++++++ include/linux/serial_core.h | 6 ++++ 3 files changed, 45 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 56082265e8e5..5d07a8c1eadb 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -436,6 +436,9 @@ RTC SERDEV devm_serdev_device_open() +SERIAL + devm_uart_add_one_port() + SLAVE DMA ENGINE devm_acpi_dma_controller_register() diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 179ee199df34..005190b279b3 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3217,6 +3217,42 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) } EXPORT_SYMBOL(uart_remove_one_port); +struct uart_port_devres { + struct uart_driver *drv; + struct uart_port *port; +}; + +static void devm_uart_remove_one_port(struct device *dev, void *data) +{ + struct uart_port_devres *res = data; + + uart_remove_one_port(res->drv, res->port); +} + +int devm_uart_add_one_port(struct device *dev, + struct uart_driver *drv, struct uart_port *port) +{ + struct uart_port_devres *res; + int ret; + + res = devres_alloc(devm_uart_remove_one_port, sizeof(*res), GFP_KERNEL); + if (!res) + return -1; + + ret = uart_add_one_port(drv, port); + if (ret) { + devres_free(res); + return -1; + } + + res->drv = drv; + res->port = port; + devres_add(dev, res); + + return 0; +} +EXPORT_SYMBOL(devm_uart_add_one_port); + /** * uart_match_port - are the two ports equivalent? * @port1: first port diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index d657f2a42a7b..d0911f04706e 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -771,6 +771,12 @@ int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port); bool uart_match_port(const struct uart_port *port1, const struct uart_port *port2); +/* + * UART devres + */ +int devm_uart_add_one_port(struct device *dev, + struct uart_driver *drv, struct uart_port *port); + /* * Power Management */