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: 13052175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEC25C43217 for ; Tue, 22 Nov 2022 10:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbiKVKXy (ORCPT ); Tue, 22 Nov 2022 05:23:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbiKVKWL (ORCPT ); Tue, 22 Nov 2022 05:22:11 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC6F4E42F for ; Tue, 22 Nov 2022 02:21:53 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id l39-20020a05600c1d2700b003cf93c8156dso10917223wms.4 for ; Tue, 22 Nov 2022 02:21:53 -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=eiLZAOTjut1NTIYuD+hnX6BUQSaMJCdsVJWmDKvpz9hohI8u4pp88Z8T393AXyqzpw WbgfqYI4ZfWfUWAneysZPhjTHlR/JPqUpWjxRHASiEhqmBvnfcEDT0QM2JbM1DuOkRlz zNgPYaC05UVOltfFMpLoVAfP4SdICCqjznne1fW2w/ZGRLY8Waf5rksL3hgsAKmDchdk ymW4yWQnwfxuJjg8H9bIMG4/A0Bd53hNdfSwAb/7t15pEnmmIHk8okv9HclbP56k56AI jO8ErNmzSeR33aBqpFvBMrYdaZsXyLeXiNiZvF5q9VBygIVghiB0Ywgy9OOw8IVx3Tvn AAag== X-Gm-Message-State: ANoB5pnmMLlBdDlbbrM0Qe1/js4MPw5XEVttMCFiY8qKRQiaF5EO4t5W Qnib5FS0Sm5avqaNBV4y2emvOg== X-Google-Smtp-Source: AA0mqf6F5CKYp1cj3ICGkEzObFA7z8uPbsQFkopSwvQDdKVO4tzZn/XDhXCeCyEy5WVeeswdbWEjag== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 */