From patchwork Thu Oct 3 15:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 832400 Delivered-To: patch@linaro.org Received: by 2002:adf:8b52:0:b0:367:895a:4699 with SMTP id v18csp342962wra; Thu, 3 Oct 2024 08:23:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWlEnIxyzXKJC3GO1A4rpmMaxdwM8G1n6Ta7Gphyl2tj3pX0lDF67YxHy8iqQrPA1rBZh8NnA==@linaro.org X-Google-Smtp-Source: AGHT+IHzLWNrVHC5GLyuOy65pF9CLzUkxvzkhE9x0Ef+ICqztXrzP2UqxNy9iEYtOPP3G9//V1vj X-Received: by 2002:a05:6e02:1d19:b0:3a3:3e17:993f with SMTP id e9e14a558f8ab-3a36593a386mr64062635ab.8.1727969035053; Thu, 03 Oct 2024 08:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727969035; cv=none; d=google.com; s=arc-20240605; b=PxD/uAClpRJbQS7kqpsA/59KFeLZIAfdS2H5THNDO+5Nl7KW6cw8agFNYfbsHQnLOB kOoBLj3QO7/9xOonSyse4i/Xgljdy0FMXBqH0ZkRU8g0dEmy5PGTzGYKr+0/3idBZ7Oc 96leaqqROp4StntDkTsZfP84Jqa+gs5zDCbX/g4cAeBcAI5H1fl5IYkyq/uYbvatlgYD pIHnjZuU0OvaEyR/Qe3e9N2gQnkoe3zFN1GkdSBHY5/4EHwBxs5zNee3xfPsv5bZEgdK HweoFiVXRJDOVQFn6JDFuvn7B4Jx5jU1phtqBaEY0NNlsN25SHj/eiSy94t6ARCLDrn5 dPaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IPYJafKN3Kt/xHB/DNZ6P2xS+0mBigy9jMHqZFqQF8Q=; fh=MFsJz/6NgpQprpwvNv8CqsrWK6sST7rgnGXBPmh9Hfs=; b=Vk8VAtuqJSNzuc+H+U3jluCzkgzol+A/JdahS+RejR5ZrODKXzVW8D6lK6WHAkWQc0 vpAnwOoCX0hXTVfwbScY47hnO1eg0ZKgd7CFeX5aFVQv9QljqmMT1iSbEDgBMDMdwWUF a4BowF5n4iQxtFhoeR1bciX/dgawfs7d67eQsmU7Mx1JL1FX+Xzw9Z+o5464fgpQ8LbF aqGGpPZHRAxEea+W0GMnMuDRbaiVTLSiD2G6NlEyusXVKOumRdJURqBYp6HJa6Kd1FrN J4/emhioJ9QGLMvzDAu5t+upI7UoBgNkcocFfWIpUVgUpb+zVJ6fQe35lJvSwnz85XDF vd8Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BMyXso8I; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id e9e14a558f8ab-3a3713ac016si6345015ab.91.2024.10.03.08.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:23:55 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BMyXso8I; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B582188E4A; Thu, 3 Oct 2024 17:23:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BMyXso8I"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C189988D9F; Thu, 3 Oct 2024 17:23:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 67C1B88DE9 for ; Thu, 3 Oct 2024 17:23:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-37cfa129074so864104f8f.1 for ; Thu, 03 Oct 2024 08:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727969019; x=1728573819; darn=lists.denx.de; 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=IPYJafKN3Kt/xHB/DNZ6P2xS+0mBigy9jMHqZFqQF8Q=; b=BMyXso8IT/TFgVYeck/qsxasL8CapTw405LOxdkZYIBB+sUSdbfMk+s+7ZrH1udXJ0 bwIGxcxRZUBcPUPlUqn35m6ccCc392oa1REJp1rCMh5DI+yD8saGlma/PXV6XxoXcTV4 R9hdYBPlmINHiMweGnAsfQnJzvLa7TM74C7mYpz/NkKiAlDwx+AFtVN6YfL88NvwdlIS sxxZhZiAzwwKgt59dACpvE/mns4/NJTpDHatj5legbEJ1JGP+bQkw2Y6dckwDRtRGmOl ljQx6d6bvZyVdvvh7+vkU46lqBzCcGrjq3TAnE3ANJnNl6LNAutzXp9hxN6W1OnhoB1Z icVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727969019; x=1728573819; 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=IPYJafKN3Kt/xHB/DNZ6P2xS+0mBigy9jMHqZFqQF8Q=; b=iJU925H9kQfT40irShDkJTZgMZTKyCp9s+LCf54UngQp2tACSvIImUlT1rQcwvPYks 6VwACq8x+PzjX8I1MfUB3GmuhtZoF8wh12edZcYKUJC+mHKr2mjyLVsdgfFRe2e+Zf0H mslNXnh0lofZ1tUB6GkYDR/2rnrr7zJfAItN7UF3PyqPpq9+nIZpTv/lH8ELmayhOHI/ OOqLoL1CsufoMsElHNrlVWi8i7DKgEiR4HGuFiKywOBKSg8ssZzM4zfonsmsi8eDdgg1 9LvFRsYV0hxQV60DLfYFmYgxbXBNm+WOuxJc0hH/slYr7CAVXlB104VZewHRhZkuszXW x7rw== X-Gm-Message-State: AOJu0YzfwqVr9BMpCO7EkkZoK7yDC3kJ3pQjoyJrJ3FSHFK9sAjWQAqb x26PhfZZXkkwTKMDpHSc65CsGGmAg5VbgDbi6zBjvS/bASP9b1en/CBtY7jl82v8ijLQiKMeJrz 1bAT0Rg== X-Received: by 2002:a05:6000:10c7:b0:37c:d512:d427 with SMTP id ffacd0b85a97d-37cfb9ddfc2mr4654329f8f.35.1727969018667; Thu, 03 Oct 2024 08:23:38 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:d888:7a58:deed:47d6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d081f7482sm1506220f8f.8.2024.10.03.08.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:23:38 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Raymond Mao , Maxim Uvarov , Tim Harvey , Anton Antonov , Jerome Forissier , Joe Hershberger , Ramon Fried , Tom Rini , Maxim Uvarov , Simon Glass Subject: [PATCH v11 01/29] net: recv(): return -EAGAIN instead of 0 when no cleanup is expected Date: Thu, 3 Oct 2024 17:22:47 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Note: patch posted separately [0]. [0] http://patchwork.ozlabs.org/project/uboot/patch/20240927142038.879037-1-jerome.forissier@linaro.org/ Some drivers do not behave properly when free_pkt() is called with a length of zero. It is an issue I observed when developing the lwIP series [1] (see "QEMU CI tests for r2dplus_i82557c, r2dplus_rtl8139" in the change log) and which I fixed incorrectly by not calling free_pkt() when recv() returns 0. That turned out to be wrong for two reasons: 1. The DM documentation [2] clearly requires it: "The **recv** function polls for availability of a new packet. [...] If there is an error [...], return 0 if you require the packet to be cleaned up normally, or a negative error code otherwise (cleanup not necessary or already done). If **free_pkt** is defined, U-Boot will call it after a received packet has been processed [...]. free_pkt() will be called after recv(), for the same packet [...]" 2. The imx8mp_evk platform will fail with OOM errors if free_pkt() is not called after recv() returns 0: u-boot=> tftp 192.168.0.16:50M Using ethernet@30be0000 device TFTP from server 192.168.0.16; our IP address is 192.168.0.48 Filename '50M'. Load address: 0x40480000 Loading: #######################fecmxc_recv: error allocating packetp fecmxc_recv: error allocating packetp fecmxc_recv: error allocating packetp ... Therefore, make recv() return -EINVAL instead of 0 when no packet is available and the driver doesn't expect free_pkt() to be called subsequently. [1] https://lists.denx.de/pipermail/u-boot/2024-August/562861.html [2] doc/develop/driver-model/ethernet.rst Signed-off-by: Jerome Forissier Reviewed-by: Simon Glass --- drivers/net/eepro100.c | 2 +- drivers/net/rtl8139.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c index d18a8d577ca..f64dbb7d6a1 100644 --- a/drivers/net/eepro100.c +++ b/drivers/net/eepro100.c @@ -678,7 +678,7 @@ static int eepro100_recv_common(struct eepro100_priv *priv, uchar **packetp) status = le16_to_cpu(desc->status); if (!(status & RFD_STATUS_C)) - return 0; + return -EAGAIN; /* Valid frame status. */ if (status & RFD_STATUS_OK) { diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c index 2e0afad089f..5f4b1e2d3a0 100644 --- a/drivers/net/rtl8139.c +++ b/drivers/net/rtl8139.c @@ -433,7 +433,7 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, unsigned char *rxdata, int length = 0; if (inb(priv->ioaddr + RTL_REG_CHIPCMD) & RTL_REG_CHIPCMD_RXBUFEMPTY) - return 0; + return -EAGAIN; priv->rxstatus = inw(priv->ioaddr + RTL_REG_INTRSTATUS); /* See below for the rest of the interrupt acknowledges. */