Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7617163rwn; Wed, 14 Sep 2022 01:22:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7EFJg2pP6ABPUI5MMva9H3siSEBf6FCyaKoEn9wBeoBnmK0yXmKBoHWd+5cat9HV8rCW+V X-Received: by 2002:a05:6402:2905:b0:452:2604:ae96 with SMTP id ee5-20020a056402290500b004522604ae96mr8365995edb.31.1663143767049; Wed, 14 Sep 2022 01:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663143767; cv=none; d=google.com; s=arc-20160816; b=hRMT/Bd0Ko6f1IPGsKyjIW8hABBU4dODyOD7TgkE+GmCHh4C5bhfTZAEOwoITspNdt 2X4+WyR+5o1EdORTab+ZtLnWFnZk0G1coC9fluRbfqHCGRY5cxRRirRUc8rWcb21F/K3 kFycrFro1lDiiJ4DVZDa9GtpCtSjSbJ3doSx4VNxZZW0BSlAaKejisEv5dCgZEupNN84 lbZm5vAzQRsxtXZZFX1chyDxTszULOskjVhrvpcWMSmINOXYnsbW3yAdVYebRCMn+CAO GL3wGwM4KOj9QYVOvv/xNlBOX5rUiqN/GsTz4qlr3jg3oOSUyCibt+uE5L3T6qVs3Yo6 nmAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E3uwB8CqWVlPJdmYFGu1eVYpx1JpXqpegdhCF2Dn9pA=; b=EU7/MlVOA3KHqMgXPY+EaYk6AUwQQF4BjhJXzsPZK01vyqzbUXoVlGAWw4LWebsvSY zm9Au8bkmfvAGtj8o5jKyL7MT++AHyvJtLrx0+TjA448YxBuI95Yo6Vest3e+lWpoIOk Mh95foJxf0d96P5bNQy+0tExnNPGjGA+nGTjXv4Fj8B0gxGYJ5mMJ+NSmiJXPS6Y6n1p bYyMZzvpofumVzDiiIkq7/+7dWQawv2w+vAiVy3/cjSL+n1+d/BM+0F7wDW73f765bPl G9XcZuT2GyLZwvnSQixED/YWgP4WmTBtHOM+FgwjUVjnrwvt/OxuRm/hm5h3PLArDJal +FzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G2z63NBe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s20-20020aa7d794000000b0044e9151d561si11284715edq.542.2022.09.14.01.22.22; Wed, 14 Sep 2022 01:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G2z63NBe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230309AbiINIQE (ORCPT + 99 others); Wed, 14 Sep 2022 04:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230058AbiINIPv (ORCPT ); Wed, 14 Sep 2022 04:15:51 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A828710549; Wed, 14 Sep 2022 01:15:50 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id y9so11155665qvo.4; Wed, 14 Sep 2022 01:15:50 -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=E3uwB8CqWVlPJdmYFGu1eVYpx1JpXqpegdhCF2Dn9pA=; b=G2z63NBey6mFbnL8i3cvE83J02RhQqveqTl3DsSMswps6rOR1S+R32HI4mouP30Va9 FPdAZ7eSLooqa+81j0vK4CfzcQMic1WPM/hllalMM0TUO7d5MXvknHP+00ogn8uqIxlw FqguQlFwXnV8gNoYShd2TWwXPOPPGXkG6cffddCojrNQeNzv6630pcr1ktrs/Azls8/U mYl4XOEZNY1fbAI2JFYW2dHLjsRY3hd7gn0Gje5C2iMCOS9JMW0oAMAwRfPGSIUe2uwW uYj9jFT2jPLRa79KEVigywAKb2naNzBZ4cyJ2tMilZEyrI5uslIlqtOK4Yr2NzVyoxpS QrNQ== 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=E3uwB8CqWVlPJdmYFGu1eVYpx1JpXqpegdhCF2Dn9pA=; b=l+M30Tf4Nj0NXqc7pLWNl3MkNZSj2/6JhqjGgxiPg1LG4Ab5Z5sXWZexdNF5A6jGrV EN9ymc9++9H3FvXuepID1MZbjP6UN2RqGQhkJGkn0sWnwKFHNbI4cRw6wSXqgkV6Roao mogJ8cLiWJxxUGA3eR9va08gmM0JxOXjOQcSKOd70G5iqRwBbnCp/CtKwWmt8nOIKRjd iLwnQW+KNYuTRjBOF4mWHBi1wBhhzkPiDsnnEU7LzNISbD5tdZtWHCGKOsHUheEoW9uc BEl+Y1btTHGb68l47yxQsB70TiuA1NmqcHbGgsKwgojnQARReIA477AxH9ZpGfRcoaSt peHg== X-Gm-Message-State: ACgBeo0ikN0Sd8hwPKKfbbpPazaZsj2YxzitWG9AxRbKLZvSB3J+IG4F AwGrR7+8ssBB45o2cmiMfg== X-Received: by 2002:a05:6214:5181:b0:478:69bd:38c5 with SMTP id kl1-20020a056214518100b0047869bd38c5mr30478259qvb.59.1663143349792; Wed, 14 Sep 2022 01:15:49 -0700 (PDT) Received: from bytedance.attlocal.net (ec2-52-52-7-82.us-west-1.compute.amazonaws.com. [52.52.7.82]) by smtp.gmail.com with ESMTPSA id r18-20020a05620a299200b006ce7cd81359sm1497995qkp.110.2022.09.14.01.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 01:15:47 -0700 (PDT) From: Peilin Ye To: Eric Dumazet , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni Cc: Peilin Ye , Cong Wang , Kuniyuki Iwashima , Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye Subject: [PATCH net-next 2/2] af_unix: Refactor unix_read_skb() Date: Wed, 14 Sep 2022 01:15:41 -0700 Message-Id: <6fd03b42db6b44142e517f85902e99c720277586.1663143016.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <03db9765fe1ef0f61bfc87fc68b5a95b4126aa4e.1663143016.git.peilin.ye@bytedance.com> References: <03db9765fe1ef0f61bfc87fc68b5a95b4126aa4e.1663143016.git.peilin.ye@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye Similar to udp_read_skb(), delete the unnecessary while loop in unix_read_skb() for readability. Since recv_actor() cannot return a value greater than skb->len (see sk_psock_verdict_recv()), remove the redundant check. Suggested-by: Cong Wang Signed-off-by: Peilin Ye --- net/unix/af_unix.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index dea2972c8178..c955c7253d4b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2536,32 +2536,18 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg, size_t si static int unix_read_skb(struct sock *sk, skb_read_actor_t recv_actor) { - int copied = 0; - - while (1) { - struct unix_sock *u = unix_sk(sk); - struct sk_buff *skb; - int used, err; - - mutex_lock(&u->iolock); - skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err); - mutex_unlock(&u->iolock); - if (!skb) - return err; + struct unix_sock *u = unix_sk(sk); + struct sk_buff *skb; + int err, copied; - used = recv_actor(sk, skb); - if (used <= 0) { - if (!copied) - copied = used; - kfree_skb(skb); - break; - } else if (used <= skb->len) { - copied += used; - } + mutex_lock(&u->iolock); + skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err); + mutex_unlock(&u->iolock); + if (!skb) + return err; - kfree_skb(skb); - break; - } + copied = recv_actor(sk, skb); + kfree_skb(skb); return copied; } -- 2.20.1