From patchwork Tue Mar 7 15:55:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 661545 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 5F812C678D5 for ; Tue, 7 Mar 2023 15:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbjCGP46 (ORCPT ); Tue, 7 Mar 2023 10:56:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231549AbjCGP4Q (ORCPT ); Tue, 7 Mar 2023 10:56:16 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136FD898C3 for ; Tue, 7 Mar 2023 07:55:46 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id t15so12605233wrz.7 for ; Tue, 07 Mar 2023 07:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678204545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PRjk8VOppnGqzOz7XErLSEL3dWYMpgLTb6kuNQ17jK8=; b=eZrAbeN4kKHrj/W0DHIGzXlvGANWW+5yMvHLqz3FFmu6qH7AU6P+SItcRoa7rfBPDm xdLgqEe/47cGXLKlgqRqoxlD0V4sjR8fHv5jDSJo/cS4f5W50o33s8Ykpc5VoyWcEEMH AqG5Rl1u4TeRXnnxCGZ5q33dhoMQANbSoDjzTZIHtSy+r53aEZIVo+wpqtHAq8iDF74L 0vx8wQdFLpqCmqHGJRESnN4NxQ7j82BItCzmjQunVI6umHiIqTtG/loLmjvPUsmD0CzL 1zkLZ2LroIsxvaydN65lm0WfPcedfi6BeVpUSWbn3SegwmpCkbdsEZV+gNoO2ibQjCmQ u+pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678204545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PRjk8VOppnGqzOz7XErLSEL3dWYMpgLTb6kuNQ17jK8=; b=JHL/Y5JxScz/10r+f/wON/ClyGmHcyAvM23IS4CNKJyXJIayhkslvJk8/FvHiouJvM LaRRJijZrP4SO9q03kU8N97YAoYj0xBVZz0Q3FxPjtuAJUVfxKZusA+s04OXN1YFBenE RkQe1ZckM6vrOjesTUTOzcMhCyhYp1s5IDS1BzVPTZ1TuVL0UEy4yMxbq0LVP/3OIcXt kw3v/scvgJWmXgWjuRRRLR9QdLVOCRl/9RPmeLJR6qzLNMxRuhomQ2T2uU3QFTyPBvpv 1pWEAUDkjNUrl/o4yIwIzhtKGtYx8Z4nLBtz+Kkk3BPDnmwXYKdAW4LbcdWIa1ETRyCb bhOg== X-Gm-Message-State: AO0yUKUKfhoVhFtiGrHqareGq6axB0LksHvG00slU7wS/M+sH74PkwCj NE1v0Gzwsbq9iyOd8rX63lqzmA== X-Google-Smtp-Source: AK7set/N/5BkOLByxbmUAWxPDJR0jyVXI564X6f26/BBqGzsj0yvuKvIsK2Ppkj/Voswj+bqthK4HQ== X-Received: by 2002:a5d:6148:0:b0:2c5:5335:73f3 with SMTP id y8-20020a5d6148000000b002c5533573f3mr14139460wrt.34.1678204545343; Tue, 07 Mar 2023 07:55:45 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id t14-20020a05600c450e00b003e1fee8baacsm18115389wmo.25.2023.03.07.07.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 07:55:44 -0800 (PST) From: Srinivas Kandagatla To: agross@kernel.org, andersson@kernel.org, gregkh@linuxfoundation.org Cc: konrad.dybcio@linaro.org, jirislaby@kernel.org, bartosz.golaszewski@linaro.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 1/2] tty: serial: qcom-geni-serial: check correct dma address before unprep Date: Tue, 7 Mar 2023 15:55:41 +0000 Message-Id: <20230307155543.31021-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org looks like there was a typo while checking validatity of tx_dma_addr, the code was checking rx instead of tx. This can potentially lead to memory leak, this patch fixes the typo. Fixes: 2aaa43c70778 ("tty: serial: qcom-geni-serial: add support for serial engine DMA") Signed-off-by: Srinivas Kandagatla Reviewed-by: Bartosz Golaszewski --- drivers/tty/serial/qcom_geni_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index d69592e5e2ec..5972b5c317d3 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -596,7 +596,7 @@ static void qcom_geni_serial_stop_tx_dma(struct uart_port *uport) if (!qcom_geni_serial_main_active(uport)) return; - if (port->rx_dma_addr) { + if (port->tx_dma_addr) { geni_se_tx_dma_unprep(&port->se, port->tx_dma_addr, port->tx_remaining); port->tx_dma_addr = 0; From patchwork Tue Mar 7 15:55:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 660401 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 60FCFC6FD1A for ; Tue, 7 Mar 2023 15:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbjCGP5C (ORCPT ); Tue, 7 Mar 2023 10:57:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231321AbjCGP4b (ORCPT ); Tue, 7 Mar 2023 10:56:31 -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 0A6E592727 for ; Tue, 7 Mar 2023 07:55:47 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso10712747wmi.4 for ; Tue, 07 Mar 2023 07:55:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678204546; 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=P15p35qbKcAqVqsT9ttAQG6NVrmbwLtDEUCun7OYD7M=; b=xG1h0yEbTGisiKYmRDyUt8v7SeyNiOl2wgMRcDZpR5hlJwpb/2UoUsll2kLQyml10I mQjMYhtx6jahxTEtVgY+PGUg31xcm4N1EjRDKnoAohkSG3upA2lEprddJS1yNWjLTrwS dw+1AmXgku8l64hHuiJsasVntg4iljribigsUpuihJLdwe3Rck8lB7AlqC7feO0bBkpJ TUDkrZ8NYgWbJbhaVWU9VSLPXdoSmTn/dmts4wmRgeTmtfJgzAARoaKN4YCo0OV7zxRS BNRsQgjfy4uBpSsqICwRDTh24Gm4AfFAv7j1vt5I+9G8cmsfDYHprb70kX7aanGixb9v ikfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678204546; 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=P15p35qbKcAqVqsT9ttAQG6NVrmbwLtDEUCun7OYD7M=; b=q/FIofmfKZkgOjptCjcSDqlB9i9CTzJTfVnrw5zLKSSw8sqMhRNaFzKlNwBtA44P2E PjlGAP/iLAKbg4jwMUc6sRWf1REPGDF1Iv6gg9dswEWPEdaSkSFaC/AeA9lHsqIAkh2R SKpGwcsO7b8c7OD1EvZMEbU/HOXIQFfS1dhQ91/pMiB75IuEzNUtMx/azLdgX6V66Yrq SMbHYw19Kc56Bm2rCtYPyGPuT4TfVXtp9h7HDyvmVxnk0lFv+JOaX1M70UnaYmbM5u+p Qaw67paitHUB/c0ZVBNHgXJI0ogCx2mXARZx++GTl9YIS5kfnoiKwYdlpk8ZvY4pKlW2 ZwrA== X-Gm-Message-State: AO0yUKUuCUUK/n1IpoOQw1xsb/bSqTiYue5UfEf8KksyKD011BGnyMdk tZ69ah7Kp4xHevk3vXCWO8JZ/A== X-Google-Smtp-Source: AK7set9f/DHvbv2XVBWNvZ1EineBTV+wgavrkys7oed6bmp6CNQz1UnFeQUBASHcvALv/DpMVcfJHw== X-Received: by 2002:a05:600c:1c1f:b0:3eb:3b7e:7b89 with SMTP id j31-20020a05600c1c1f00b003eb3b7e7b89mr13606520wms.3.1678204546445; Tue, 07 Mar 2023 07:55:46 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id t14-20020a05600c450e00b003e1fee8baacsm18115389wmo.25.2023.03.07.07.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 07:55:45 -0800 (PST) From: Srinivas Kandagatla To: agross@kernel.org, andersson@kernel.org, gregkh@linuxfoundation.org Cc: konrad.dybcio@linaro.org, jirislaby@kernel.org, bartosz.golaszewski@linaro.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 2/2] tty: serial: qcom-geni-serial: check for valid size before starting dma Date: Tue, 7 Mar 2023 15:55:42 +0000 Message-Id: <20230307155543.31021-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230307155543.31021-1-srinivas.kandagatla@linaro.org> References: <20230307155543.31021-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Check if there are valid length of bytes to transfer before starting dma. without this check we can see below kernel warning when we try to map a zero size buffers. ------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at drivers/iommu/dma-iommu.c:1046 iommu_dma_unmap_page+0xe0/0xfc Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 6.3.0-rc1-dirty #347 Hardware name: Qualcomm Technologies, Inc. Robotics RB5 (DT) pstate: 804000c5 (Nzcv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : iommu_dma_unmap_page+0xe0/0xfc lr : iommu_dma_unmap_page+0x38/0xfc ... Call trace: iommu_dma_unmap_page+0xe0/0xfc dma_unmap_page_attrs+0x30/0x1ec geni_se_tx_dma_unprep+0x58/0x80 qcom_geni_serial_isr+0x350/0x750 __handle_irq_event_percpu+0x58/0x148 handle_irq_event_percpu+0x18/0x4c handle_irq_event+0x48/0x88 handle_fasteoi_irq+0xb0/0x130 generic_handle_domain_irq+0x2c/0x44 gic_handle_irq+0xd4/0x140 call_on_irq_stack+0x24/0x4c do_interrupt_handler+0x80/0x84 el1_interrupt+0x38/0x6c el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x64/0x68 cpuidle_enter_state+0x1e4/0x310 cpuidle_enter+0x3c/0x54 call_cpuidle+0x1c/0x40 do_idle+0x204/0x260 cpu_startup_entry+0x28/0x2c kernel_init+0x0/0x12c arch_post_acpi_subsys_init+0x0/0x8 start_kernel+0x3cc/0x74c __primary_switched+0xbc/0xc4 Fixes: 2aaa43c70778 ("tty: serial: qcom-geni-serial: add support for serial engine DMA") Signed-off-by: Srinivas Kandagatla Signed-off-by: Bartosz Golaszewski Reviewed-by: Konrad Dybcio --- drivers/tty/serial/qcom_geni_serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 5972b5c317d3..bb63a00f4c07 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -637,6 +637,9 @@ static void qcom_geni_serial_start_tx_dma(struct uart_port *uport) xmit_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); + if (!xmit_size) + return; + qcom_geni_serial_setup_tx(uport, xmit_size); ret = geni_se_tx_dma_prep(&port->se, &xmit->buf[xmit->tail],