Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1084771rwj; Sat, 29 Oct 2022 16:38:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5IRC9FtwkVgyQJVxU28zi6XQuRrRlj/dSvUXWjI4kAaKi5A0S+QZZ5hEOhcITFHOoyizLB X-Received: by 2002:a17:907:2be9:b0:7a1:11a9:1334 with SMTP id gv41-20020a1709072be900b007a111a91334mr5644975ejc.131.1667086711846; Sat, 29 Oct 2022 16:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667086711; cv=none; d=google.com; s=arc-20160816; b=RLkfBV/D6zGxgAqWrszkXcEX1bq9UoUgvat8xIWIEVITgLBlid4bzQI2VnnLC4mc+r J+Jll13fFBklnja6FoJ14URQfDeNtW2gU2C8qxw/QhLiAg33BOxxqxmOGbcoLJsDhGuG eXTmqA5/0dfg78Fmv30lcj9YltMQvqGeu3HSGlicA1JaNhE8cXjVKfbni+oj+uEPjque oN3XqVczzAAOE/1XCO8jCkIG28pX3SOkE8WJY8Ep/92nSzU+rQ37EHwg/ohwiV2LBZBS ZUadBGDIQQjqu55LPgpmINVIkoYeWOC73T+PdEfa6Axw5i/JwXgzmO85FPICodOvnwzI UzJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MQOuXgEd4uijladGhvf42ViTnATMp5s51KNIKFeH+uw=; b=PuDE9ULgHAQ5AnxltR9TUKKnifd6Q4lK6C+ym+xfXpeCnq7/gvzGBVjYCZ+8RTNm07 dHim15/PwuHxHaYDKO4dr1nSRS0dWjsFV8bEsUpwOhV4xSkk6B2V7oRHDDWHY1tsaDV/ z6kJ3hm2JnaJBTScLhv9L/k7gyPWd5IVmL5cunIhuDDOq00VwE5xk9/55iariUuRpqyi mc4jYAZW3fgwsiW0LF32YBC5Z8wCglSuQTl/AXajdu9b7fglfuP+nlOBj90lOKNjAZn2 SkiZUJM/TCZ5uZnph7xQrNl46ojnY1UkfRRUd8YZzH5rohuRxyxgdG3BlQ71avjRCwop oXJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=uRfPySHb; 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=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020a05640227d100b00462846fc76fsi3355586ede.108.2022.10.29.16.38.06; Sat, 29 Oct 2022 16:38:31 -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=@linux.org.uk header.s=zeniv-20220401 header.b=uRfPySHb; 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=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiJ2XTF (ORCPT + 99 others); Sat, 29 Oct 2022 19:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiJ2XSx (ORCPT ); Sat, 29 Oct 2022 19:18:53 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5BB2F00D; Sat, 29 Oct 2022 16:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=MQOuXgEd4uijladGhvf42ViTnATMp5s51KNIKFeH+uw=; b=uRfPySHb4xVQmQ1rA28MZQ3S9b d/25b4ehxWwsFjmU1ZCeQjljNYhdwuJHQmFqFrPVtCdCkmC5Fv1xMg/fGw6NXGfi92bewhpfVFSxN UHtTN332gAocwbX5+sQkAHscJNBQX7Bw8KFizNBcbC+IENqCVMwwaET1nSOyv+FYfjBrWO++VTbLi EFyOu0fMD0G9/BvcEJ6vZQRtWAnHV7oEF9qn+MI8SqAoifjYC/ZEHLM5ceWYwZ8YqNIqJyYdXHLYZ BPu9H+MnQT9xWs2mhqAX52f04PlTWl+vSFMfOLH2byDL25q+4k3wxe03HfksQ6T/ctXA7jK6NG10G vYysDuwQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oov6J-00FOKj-2W; Sat, 29 Oct 2022 23:18:51 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH 05/10] [elf][regset] simplify thread list handling in fill_note_info() Date: Sun, 30 Oct 2022 00:18:45 +0100 Message-Id: <20221029231850.3668437-5-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221029231850.3668437-1-viro@zeniv.linux.org.uk> References: <20221029231850.3668437-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 fill_note_info() iterates through the list of threads collected in mm->core_state->dumper, allocating a struct elf_thread_core_info instance for each and linking those into a list. We need the entry corresponding to current to be first in the resulting list, so the logics for list insertion is if it's for current or list is empty insert in the head else insert after the first element However, in mm->core_state->dumper the entry for current is guaranteed to be the first one. Which means that both parts of condition will be true on the first iteration and neither will be true on all subsequent ones. Taking the first iteration out of the loop simplifies things nicely... Signed-off-by: Al Viro --- fs/binfmt_elf.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 4190dafd2ec4..e990075fb43d 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1866,7 +1866,14 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, /* * Allocate a structure for each thread. */ - for (ct = &dump_task->signal->core_state->dumper; ct; ct = ct->next) { + info->thread = kzalloc(offsetof(struct elf_thread_core_info, + notes[info->thread_notes]), + GFP_KERNEL); + if (unlikely(!info->thread)) + return 0; + + info->thread->task = dump_task; + for (ct = dump_task->signal->core_state->dumper.next; ct; ct = ct->next) { t = kzalloc(offsetof(struct elf_thread_core_info, notes[info->thread_notes]), GFP_KERNEL); @@ -1874,17 +1881,8 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, return 0; t->task = ct->task; - if (ct->task == dump_task || !info->thread) { - t->next = info->thread; - info->thread = t; - } else { - /* - * Make sure to keep the original task at - * the head of the list. - */ - t->next = info->thread->next; - info->thread->next = t; - } + t->next = info->thread->next; + info->thread->next = t; } /* -- 2.30.2