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: 13164013 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 72216C6FD1B for ; Tue, 7 Mar 2023 15:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231616AbjCGP46 (ORCPT ); Tue, 7 Mar 2023 10:56:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbjCGP4P (ORCPT ); Tue, 7 Mar 2023 10:56:15 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A2592704 for ; Tue, 7 Mar 2023 07:55:46 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id l1so12569731wry.12 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=Qnnls3vbzEn5ymBLc9spoSiBf5XK0Lx1sLGj+6qR9nrDwVsfMtb23yY57NqXCT6BZY A7b4KTdd1Owq2/Cf+UIDYG/9/pgIvsv7nWQpJg1y44uJDxH94ok56QUuC+xBLMb39Row 9QlihDglzFmUAqZgChFteFg7zZLrwhDspOwR+CSqpFQQE4wH2Dp2qX5+sazEdCWJLxJ8 ONR3hqST5RgI+HYejysGvz/yMTmt/qYbdtdcDcLueCQe+8h23hQlW/h3vOF4dTMay0bI Fzgz0SmXUQUBetkVuO88sDhhXDh7MmPPLW54adbiH4xZg3OEdyyEBO0+wtlwQlPTcQtl cNMQ== X-Gm-Message-State: AO0yUKU1tuJwuKZWbZSo79C5nAB9RpHPIIyDoWQntUS/NT8YYpZV7lbW FI/8J27nMH6I4FWq/K9Dky4kzg== 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-arm-msm@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 Reviewed-by: Konrad Dybcio --- 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: 13164014 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 96176C678D5 for ; Tue, 7 Mar 2023 15:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjCGP5A (ORCPT ); Tue, 7 Mar 2023 10:57:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230112AbjCGP43 (ORCPT ); Tue, 7 Mar 2023 10:56:29 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A87992728 for ; Tue, 7 Mar 2023 07:55:47 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id j19-20020a05600c191300b003eb3e1eb0caso10727929wmq.1 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=yfCaLpUrJSW7orvXx/pg3GATFK+pUzRr8a/JlzS9MX1y+qh0Vo5Wm/HlsEKpfmsSRb 8HlQVsakirjKA7iWZvN58AtJqNSGvtd250uWt2nTZ09VcDl9aUbCdDsOmGYq7LLSXOJ9 sd2+lBO10XHO1z7EDHvIRwxmmgjDoXWff4e+hVyZpiP0bRrDWgjNHcuJM70bJYZ4Hx0V tq325yhGHuJtZWVMIjfkXO5UPIAlhf7dxMfN5eMGBvmG+qg/JKyBEIiMRQMhUKSipHPM 6PRBIwFgqYnjkxbKMA6T8vxjHKSSbc55zbf2yCueoHN4fQtEyiNnydttGIrNpUmFPNNA v+Zg== X-Gm-Message-State: AO0yUKUvphU77EbWFrXryaXxYFCFG0AIGNIxbvVavLLs2VsIDDfqcfWq 55qMZt7+/R4ZsUvc353RWDtSuw== 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-arm-msm@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],