From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B9C14C8A for ; Thu, 15 Sep 2022 20:30:01 +0000 (UTC) Received: by mail-ej1-f46.google.com with SMTP id dv25so44658815ejb.12 for ; Thu, 15 Sep 2022 13:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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; bh=EUHm5YwqUsut8vOCDG8gUqHimnptxihIuTZPupLKd+w=; b=oIsRIL7UHb5uy1H8a7ihPHy/irgQmUeLrHpYfS62aKWb2o/bCxHIE9WPyF8VzZdomb wZ5KoUxZNkcXT2QeXaqZKZ+UJlRUPHNxXRHIwzInSaLL0KI3q/mb7mF8Z5wRRiuV5eUD D7FCoOdc8jROfJuLlV5uA+KgtIKNXa/dn5oYXNR8k1XsXq/ZYW4ZQ1YluyGJgVUU6ZJ3 po+mLGWVk5f2/6hZPL5pt9a2MpaMx7E9cm6+2gapZfsFfEN8NF0cPQlq9zb2Mqgrbfry nhajo4cRNX5XDG196iI3bxK/LIyKBJXZobuOuf2jd+wYuWih9l+HDqxOwQmD3VE7Dub4 7Dcg== 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; bh=EUHm5YwqUsut8vOCDG8gUqHimnptxihIuTZPupLKd+w=; b=FKSoAW0c3lk0qugsxwuWbIlBq6NpISTjAcrWny6mUHhfPueSgX4IU1dp7dNJl/hU13 2aNSB8/ZexI2l5P+8zbFpEaEfjLI/zdh6MnQpfSxxrEWR8qoTVKse5RNeaiRcbgYO02C EYBiPqWI9mVtzuCTnNK1yGC6phs3SirRUrvL1Zu7TrXnoSbZkuW9mNlPJgWdVeCKz3BQ JpVsHZvy0ztVYdVS1Kt5o1K+U850IbiddAmG1r2OnI5U+UoQxfxT81nXflYLz8iIBJbC WXEMyuJ+bMldX3ZyB98tQb42HJvR9Ea+FFU4dV9ByZFFRxzJ1wSpOusuMBQcs204/Wxw TLcA== X-Gm-Message-State: ACrzQf0P0AGw4utzZdk3J0YXMWlPJVDarLPbPov8AH5pmNrhjc/rUDaT l/76bQ2DPnCtZw/SeDQWjxHUIsgUPvY= X-Google-Smtp-Source: AMsMyM6s9925GGiS4XIQLJDs2LHEhvI9/OQ12/6LogfvtbqAUEhF5PB9+dgHAJ5gZamzhCHPYFc0tA== X-Received: by 2002:a17:906:ef90:b0:77c:7227:705 with SMTP id ze16-20020a170906ef9000b0077c72270705mr1117401ejb.565.1663273799789; Thu, 15 Sep 2022 13:29:59 -0700 (PDT) Received: from localhost.localdomain (ip-217-105-46-43.ip.prioritytelecom.net. [217.105.46.43]) by smtp.gmail.com with ESMTPSA id ci25-20020a170906c35900b0072b3406e9c2sm9607295ejb.95.2022.09.15.13.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 13:29:59 -0700 (PDT) From: Nam Cao To: forest@alittletooquiet.net, gregkh@linuxfoundation.org Cc: namcaov@gmail.com, philipp.g.hortmann@gmail.com, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev Subject: [RFC PATCH 5/5] staging: vt6655: implement allocation failure handling Date: Thu, 15 Sep 2022 22:29:36 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The function device_rx_srv does not handle allocation failure very well. Currently, it performs these steps: - Unmap DMA buffer and hand over the buffer to mac80211 - Allocate and dma-map new buffer - If allocation fails, abort The problem is that, it aborts while still marking the buffer as OWNED_BY_HOST. So when this function is called again in the future, it incorrectly perceives the same buffer as valid and dma-unmap and hand over this buffer to mac80211 again. Re-implement this function to do things in a different order: - Allocate and dma-map new buffer - If allocation fails, abort and give up the ownership of the buffer (so that the device can re-use this buffer) - If allocation does not fail: unmap dma buffer and hand over the buffer to mac80211 Thus, when the driver cannot allocate new buffer, it simply discards the received data and re-use the current buffer. Signed-off-by: Nam Cao --- drivers/staging/vt6655/device_main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index ca6c4266f010..8ae4ecca2ee3 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -826,6 +826,7 @@ static void device_free_td1_ring(struct vnt_private *priv) static int device_rx_srv(struct vnt_private *priv, unsigned int idx) { struct vnt_rx_desc *rd; + struct vnt_rd_info new_info; int works = 0; for (rd = priv->pCurrRD[idx]; @@ -837,16 +838,18 @@ static int device_rx_srv(struct vnt_private *priv, unsigned int idx) if (!rd->rd_info->skb) break; - vnt_receive_frame(priv, rd); - - if (!device_alloc_rx_buf(priv, rd->rd_info)) { + if (!device_alloc_rx_buf(priv, &new_info)) { dev_err(&priv->pcid->dev, "can not allocate rx buf\n"); + rd->rd0.owner = OWNED_BY_NIC; break; - } else { - device_init_rx_desc(priv, rd); } + vnt_receive_frame(priv, rd); + + memcpy(rd->rd_info, &new_info, sizeof(new_info)); + device_init_rx_desc(priv, rd); + rd->rd0.owner = OWNED_BY_NIC; } -- 2.25.1