From patchwork Thu Dec 29 16:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 637593 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 2EA50C4708E for ; Thu, 29 Dec 2022 16:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233658AbiL2QT6 (ORCPT ); Thu, 29 Dec 2022 11:19:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233545AbiL2QT4 (ORCPT ); Thu, 29 Dec 2022 11:19:56 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AD3212AB8 for ; Thu, 29 Dec 2022 08:19:55 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id d4so9811106wrw.6 for ; Thu, 29 Dec 2022 08:19:55 -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=oqAbnpnlAxZCZCp9Pk4QU/Xx94Xjsxer7IEB8LwGfcE=; b=CLYCYMRtgsROH78TnzkjNDFbHZS2utAHl8Z8QnooOTfxG7BBMv5TM3iAyLxJpsWNMN qHdAmpWiqODp2s1QfFjEXANyR3UuB122hm7gORFYEFVisJ7vPdROVTrpWBDMk30UzGee wakStsHPvUFzY70/dv6n348NkEq9S0gqFmEh5F2J3IWSY0bb/sNrZFcMyLl/ymjbQ6B8 BX3S5bgwhDqu1GGp6l851NMiQBnGWGy/LhZElbwCklGcjnEhFgRI23dIwjarP1V3g2F2 x4+J/vf2+tXw2GORQh0IxxkyTZWpjM0O/Xcteb9uAydF8oIbs33khNRPbtZWS+LSAel3 hrkA== 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=oqAbnpnlAxZCZCp9Pk4QU/Xx94Xjsxer7IEB8LwGfcE=; b=ykWPDPduAsI6ryfehjT/qmY8Yx5rtlmdsnuFtnNUCyYJBl1NMTbMr+Fp3xx/xpQfV4 1FOHuVyVP+OkCrdQyBD2MmuPk5fdxeQDZ/m2Cw9HU1svsjouz0As1v4fnUKrh9/QzhTI 84N8lnRzXCI5xv4ycihp9tLAe+933nnM0pgQeWlVsciTUBL45JsNFqE1Zfv9CvuDK34b uFbKM/tiI9a7oEWf+K0t78mYDeRMxv/O99ZkoxDYmmj5cVfY7AJJQZ1GRjBISd7g6oSB divOr/r4IkXBTuIK8DvzDiDfJQ9ts2VjrMcP2Jkplrc+dG855lBhlr4Qi1fI+zTPLQyE G0LQ== X-Gm-Message-State: AFqh2kpyjqhLsP04x/GWoNYiLRPunIZH6qKRY/nWONohrfrTO+o/h5Tp ANGfC5NVYatyGhPb/k9ZGGwLWw== X-Google-Smtp-Source: AMrXdXtI9+FXgBJazhiWZznWBPZzoPSLpZA99ejJ2XdgruHoxFMk1dyy5w5GnvBwYTEt+W5zapcU+g== X-Received: by 2002:a5d:49c3:0:b0:232:be5c:ec4a with SMTP id t3-20020a5d49c3000000b00232be5cec4amr22347519wrs.6.1672330793956; Thu, 29 Dec 2022 08:19:53 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:8f7a:98d8:9d8d:ced8]) by smtp.gmail.com with ESMTPSA id t5-20020a5d49c5000000b0028cf987d944sm1333199wrs.33.2022.12.29.08.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 08:19:53 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , Srinivas Kandagatla , Vinod Koul , Alex Elder Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: [RESEND PATCH 1/2] tty: serial: provide devm_uart_add_one_port() Date: Thu, 29 Dec 2022 17:19:47 +0100 Message-Id: <20221229161948.594102-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221229161948.594102-1-brgl@bgdev.pl> References: <20221229161948.594102-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 | 48 +++++++++++++++++++ include/linux/serial_core.h | 6 +++ 3 files changed, 57 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 4249eb4239e0..1d79053070f5 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -448,6 +448,9 @@ RTC SERDEV devm_serdev_device_open() +SERIAL + devm_uart_add_one_port() + SLAVE DMA ENGINE devm_acpi_dma_controller_register() devm_acpi_dma_controller_free() diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index b9fbbee598b8..996aa73705f8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3217,6 +3217,54 @@ 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); +} + +/** + * devm_uart_add_one_port - managed variant of uart_register_driver() + * @dev: managed device + * @drv: pointer to the uart low level driver structure for this port + * @uport: uart port structure to use for this port. + * + * Context: task context, might sleep + * + * This is a devres wrapper around uart_add_one_port(). It allows the driver + * @drv to register its own uart_port structure with the core driver. The port + * will be unregistered on driver detach. + */ +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 fd59f600094a..3c86b751e3b6 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -857,6 +857,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 */ From patchwork Thu Dec 29 16:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 637950 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 3C537C4332F for ; Thu, 29 Dec 2022 16:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbiL2QT7 (ORCPT ); Thu, 29 Dec 2022 11:19:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233651AbiL2QT6 (ORCPT ); Thu, 29 Dec 2022 11:19:58 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A253712A80 for ; Thu, 29 Dec 2022 08:19:56 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id z16so1343008wrw.1 for ; Thu, 29 Dec 2022 08:19:56 -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=nDpCQXfYYeEajOv2TSbXiA18Zt/t8Tes9TDsjO3NMJY=; b=yNLYjLmFkWgpBuxsj3eCtD/tewyWrBUjf/VDqz9k2I8wFreh2JLvBmkwy76s9K2bR0 NjIjDB5jdTOVn5I7OCol+10dKoOpfQDSmQsREjobtiiX+no1N6HDVDac63lGKrKVJHI7 a/dNQgrAgkkbX6eo8gyHKBWD9yzCRpHHF0r9Wv+4q7mBUQyxIEGYIw8d/V2Ev/Sv6P6o 70VS6oZnZq4wNuZ+4RA3ID0TQtRQLJnvpOtvu07/0mE5+IGovwljbG+qshXgqn8So+IN W8/Ex4HcTs7FfWUC1aXRWR1q4M9guN1IOsi0ZCSeoyBKrtN90J6A1o80zu4/EZ9dtDYs Fubg== 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=nDpCQXfYYeEajOv2TSbXiA18Zt/t8Tes9TDsjO3NMJY=; b=rzYjqxi8KX2dJHUhdssoJw7Kn4D4ceX0l7xw8ljgWwD/It2wM2vF7GuGZXgfz8XIjZ nMQOC3ctEoMgWGxRXArAOEB6TeM4M2LqDmAY8F27e0Af+FYtYSsbNkOupS9UjjJDP+0P xzdnM7uB1sBm26Xo+8MtmoyZA2J3Jf6ud32i1sCpJXHbwZZGKAT1evZVdUO/riSugpwx dK/J1uftaVq8yuPoBz/eSpVNMbyr1mCtZHfSos4mxCtNz/D5zzDm//WHVYMzaQrmtmfD 68B8JxRqObBNCrznc/WcZiBBZDgWy9myCa6kYGSy9uoWShSYctZ4lAVYy0MgSfgdxG+s 1sow== X-Gm-Message-State: AFqh2koLD32+EiWRPxDcNRYo+0YXeWBHYX0YXDz0nxQNmV+NQ+dU33c4 ZGFip+YgYz3ro+t/jeOiHRS3bA== X-Google-Smtp-Source: AMrXdXvJkZIZ8ZCse4FEIYklGaB6f5dxdugGRdR7nEI4aKVZOu1OLJno2BcF9sbWPcmY//eCfxVizg== X-Received: by 2002:adf:e383:0:b0:267:b8df:932b with SMTP id e3-20020adfe383000000b00267b8df932bmr23522542wrm.23.1672330795175; Thu, 29 Dec 2022 08:19:55 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:8f7a:98d8:9d8d:ced8]) by smtp.gmail.com with ESMTPSA id t5-20020a5d49c5000000b0028cf987d944sm1333199wrs.33.2022.12.29.08.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 08:19:54 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , Srinivas Kandagatla , Vinod Koul , Alex Elder Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: [RESEND PATCH 2/2] tty: serial: qcom-geni-serial: use devres for uart port management Date: Thu, 29 Dec 2022 17:19:48 +0100 Message-Id: <20221229161948.594102-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221229161948.594102-1-brgl@bgdev.pl> References: <20221229161948.594102-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Shrink and simplify the probe() and remove() code by using the managed variant of uart_add_one_port(). Signed-off-by: Bartosz Golaszewski --- drivers/tty/serial/qcom_geni_serial.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index b487823f0e61..7d5b51d7fb9e 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -1470,7 +1470,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) platform_set_drvdata(pdev, port); port->handle_rx = console ? handle_rx_console : handle_rx_uart; - ret = uart_add_one_port(drv, uport); + ret = devm_uart_add_one_port(&pdev->dev, drv, uport); if (ret) return ret; @@ -1479,7 +1479,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) IRQF_TRIGGER_HIGH, port->name, uport); if (ret) { dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret); - uart_remove_one_port(drv, uport); return ret; } @@ -1496,7 +1495,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) port->wakeup_irq); if (ret) { device_init_wakeup(&pdev->dev, false); - uart_remove_one_port(drv, uport); return ret; } } @@ -1506,12 +1504,8 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) static int qcom_geni_serial_remove(struct platform_device *pdev) { - struct qcom_geni_serial_port *port = platform_get_drvdata(pdev); - struct uart_driver *drv = port->private_data.drv; - dev_pm_clear_wake_irq(&pdev->dev); device_init_wakeup(&pdev->dev, false); - uart_remove_one_port(drv, &port->uport); return 0; }