Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp475780lqt; Fri, 19 Apr 2024 01:09:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnozsi3gKnXOSOVmB3sXWdi9CAHseTWIVtfz5MpLdABKNGokwWc9I7qIjv60a+e4eBvkUS2O9HQB2zZbZVynPpMjasNIgZ0DiWSzM7pg== X-Google-Smtp-Source: AGHT+IHZBaD7e4/o/PgOn03Dao7Nn/hgD5BUiD0yKy9RWNqr9WtGNqLIZrU+1vCKHGzy6oHpGg8z X-Received: by 2002:a05:690c:7448:b0:609:fec8:779c with SMTP id ju8-20020a05690c744800b00609fec8779cmr1211378ywb.52.1713514181066; Fri, 19 Apr 2024 01:09:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713514181; cv=pass; d=google.com; s=arc-20160816; b=IyYiyCsgv3ocIm8jkqsdhQBNR5QfOiVdg2fswDj1uDDRYP0qji/HTuEwWZSLacUi8Y /7RMlYGfQWlm/IGDeTMS2uMcqOkCqItt4SqLaCagHu0GLO8grNpRBNjs1kcD757euBj1 UAzVhjJC4Z1ybHZe4/d0DBX/4daSqEf0xZ7YdV3goF2P13ByJc2YDSQKihNN//kBYQb3 jVWM3/eajsLOLfN+eM5p3Y5vtiy1X2/eEEVrTkkrcrQcGyFhKyRLkenNnCoCoTofELUo 7/tFrxdboGlV0fCEXaIWOLFruJHKV3afTEdWOqKC+2k/0I0zSMmrmU+ra9lj1o3I6q4j m8Uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sv4qMMzuMYtfGdINW89xAqVS228flFLSHgv1JzItG6w=; fh=7nfK9oQZIXYCtH5CxzYkiI2WYLyi2atfVLT1idbAKj0=; b=D0F3mfl7yeV5L0Fg9B5PyoaM5vl6yeOQaN5R+S6nLhihdCKMjImt0DPZW8NssDKZha ED0DQ//+KxRjvItGP9IMCnfu8zWFGlz6DnK+uWmIwfpfpFcUK9rwONMuaUjXdR/EZj+4 HYJyoQCzXrt69UgFUNRMV85kILgK2n6mrbXzukJZfSH1dqHwq++MYRLSeYqXQ8bcWdMK pTynheqfD7sSFNri2MPvZYhg+8Tvf7uoE44NQ4WJCi7hCuwi6Kyn2m/2BRAn29/A4cMX kOmrB5QpeVsJPHcxQEIoe79F7d8r7F+ouzlQTHefeOyV+q3atSCeaknz1By3+1LfmB96 XBSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gRf7Kv+1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h14-20020ac8584e000000b004377c943cf2si1893578qth.645.2024.04.19.01.09.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 01:09:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gRf7Kv+1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D6551C20EB8 for ; Fri, 19 Apr 2024 08:09:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C2FC4EB44; Fri, 19 Apr 2024 08:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gRf7Kv+1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F194405EC; Fri, 19 Apr 2024 08:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713514175; cv=none; b=RZGUZq0a5+OTPZ/SlNiG3+ASm1j38HUoN+bYJEEXfrWR0rkD1A40Ji8qWcu9ORmNzL/eXQgWW5LgnRslPLHYzmxwnzLmBec+M/gGImHTJVBtihYeUPdnZdYUsyozHA1J1aXGCMqMs+x3FzYKW9LigBltC3oVYnvUFT25couPUKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713514175; c=relaxed/simple; bh=+2vGmxIZsR1RCaOsZaJdfGR4PG7Qb9AaMhUzcpmWI9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ee9+Tzyh92n0uIPVLh0gQ2haCGJlq9WE2zIDFz3/QHg/WcbK+SCtM4X3bbq13i7bakDOak/bd5UWh2bITGeVUyA/wKZWJAV0g+xcRQ9PAoBsc/mPLS2WbBqfDZCpOdp8TMHA+6mXYkFDvJNIRIUxS6W5M+PJj4N0TEc3xXOBQFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gRf7Kv+1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB9BEC072AA; Fri, 19 Apr 2024 08:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713514175; bh=+2vGmxIZsR1RCaOsZaJdfGR4PG7Qb9AaMhUzcpmWI9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gRf7Kv+16vUrWteJ0KWa33026iDWD6wuOWvXGKnvyp5X+h828egaO7hF/yiB6KbbT Ve2caukxwuWYN72guqQabn5JjDwuxLxY33VD3P9W9CrQwkjmvnuTicg+4eqfJBI24S ZjjpnlJM8vad3nU8JKucVPwBlhfsbeTyJlCwSL4ek4CiUD5TxO6fWGVHcOZio8C8mY 5/ejKzR58leDyBLyk+/2Y37VgvpqZyXa5kHzc0ADba3Drh8Z1x8WUDhrcfs7O69pFu /xngypL7hKe+jTlkOTgxaizRT3MtO1Jw1OyRoQj4bzTUHoLAk49UB7mVgRsNbL71ci UMPoNPa2FO9KA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Marek Szyprowski Subject: [PATCH] serial: msm: check dma_map_sg() return value properly Date: Fri, 19 Apr 2024 10:09:31 +0200 Message-ID: <20240419080931.30949-1-jirislaby@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The -next commit f8fef2fa419f (tty: msm_serial: use dmaengine_prep_slave_sg()), switched to using dma_map_sg(). But the return value of dma_map_sg() is special: it returns number of elements mapped. And not a standard error value. The commit also forgot to reset dma->tx_sg in case of this failure. Fix both these mistakes. Thanks to Marek who helped debugging this. Signed-off-by: Jiri Slaby (SUSE) Reported-by: Marek Szyprowski --- drivers/tty/serial/msm_serial.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index ae7a8e3cf467..0a9c5219df88 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -499,15 +499,18 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) struct uart_port *port = &msm_port->uart; struct tty_port *tport = &port->state->port; struct msm_dma *dma = &msm_port->tx_dma; + unsigned int mapped; int ret; u32 val; sg_init_table(&dma->tx_sg, 1); kfifo_dma_out_prepare(&tport->xmit_fifo, &dma->tx_sg, 1, count); - ret = dma_map_sg(port->dev, &dma->tx_sg, 1, dma->dir); - if (ret) - return ret; + mapped = dma_map_sg(port->dev, &dma->tx_sg, 1, dma->dir); + if (!mapped) { + ret = -EIO; + goto zero_sg; + } dma->desc = dmaengine_prep_slave_sg(dma->chan, &dma->tx_sg, 1, DMA_MEM_TO_DEV, @@ -548,6 +551,7 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) return 0; unmap: dma_unmap_sg(port->dev, &dma->tx_sg, 1, dma->dir); +zero_sg: sg_init_table(&dma->tx_sg, 1); return ret; } -- 2.44.0