Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1953069ybz; Thu, 23 Apr 2020 08:58:46 -0700 (PDT) X-Google-Smtp-Source: APiQypJ/Yon0siO13wfOCJuC+gCS9rreLVLVGTPztbpZvAqKGhAKPGaPOQ7LDfn0uueTdPFzOOtF X-Received: by 2002:a50:f0dc:: with SMTP id a28mr3103231edm.87.1587657526765; Thu, 23 Apr 2020 08:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587657526; cv=none; d=google.com; s=arc-20160816; b=WsMEQrupkZpKU5ZAZcbCTOPXexRBP31xuCuRvJZEpEj8IWvKispmS6O3xTt2/TBlXT V1tdDrgUfj742m+TqbQ78cBVgproKW9GiEHaQWLfo0zH3bHqURsqWjIpKUW8URkwKJ30 tCfu/CqAHJHmSj931o71B0okUrf5jyIjeBD9rZSg7aj66PTR+RfwTzr1UBDs+Rc4zq1y Fr2TFEu+C7A5DbvY6wb+AmzXpHAG63gqKq3nLAPso0Fyjww6DwC4RbXG9DvWP07UlyVc 6Rk1K3m8c4VXYzMOIDqFikfWUOzK47QkNScskmbw7te4X+oBuEPwsGLZRwo0H0tjTGeS 0d7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KwSXPvgUYiTHnatXM5A5YtzTm3Yeu/jjyhqkXoCcjDE=; b=f/HapW6oBVI3G2RTsznJFugrYWlSbTywFBVPwiJTo1P9cTDo0EbRSKPoBjWM+sK2ZH oQKAdbCvCoFKdjHDNyHlPz2/8+3GGJTwXCG9fEZwpVDzzXZjmoWZdTz0lcJw3zZX4xXz 7g32npilWrqcAMTiBvfICZe5KBylnc02dHxuE60kWrw4qmnJVlxeig4gqzfnDCYU3Vyv vDYduX410IBrZX+hxGKisiUt3KBpgoKhu18mlqBz0yKKP1BDlBV0jGe00ttgLW2My2DP udsxN5M7agYFl5GHB1flBy8Ii9lui5Ojy6g2LijV3HOCdEcFOsGPflyq1yg+W8R1Rjlo Zt9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hFg12bRG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n16si1283044edv.252.2020.04.23.08.58.22; Thu, 23 Apr 2020 08:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hFg12bRG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729426AbgDWPye (ORCPT + 99 others); Thu, 23 Apr 2020 11:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729230AbgDWPye (ORCPT ); Thu, 23 Apr 2020 11:54:34 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193D3C09B040 for ; Thu, 23 Apr 2020 08:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KwSXPvgUYiTHnatXM5A5YtzTm3Yeu/jjyhqkXoCcjDE=; b=hFg12bRGbQqFI+zNKj371TZHSW lvAvAaphdJwCIw2u4Xn1D3AzlFVuMW07NHIIhyJwgEAEj6mEt9EHRXRNOxx26pnQWyP5eYWngVj0m Q6C4OkHonMLdPzW7KgRqxmM/7/atqLEaML7jxwfLvytR8MN/2myv3xiU6zUAF3NzmT3LKMc4RdxHX dllTEMox+oNRv7N8LIGFwg5vTZKmksw07RFmC/ipKJDUsXDnP0wJfwxjv57aBGTGuhfgE0hjHak/W Y6W2I1k2MG01deBlrwvmsdyj/nng9IiSJUyeIUs48E7j0s8zrMxBq+IeP4zNdubD3I1nkgB+PxRRC E+x42T8Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jReBH-00018N-A0; Thu, 23 Apr 2020 15:54:27 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2C7F33011C6; Thu, 23 Apr 2020 17:54:25 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 18BC720BC7378; Thu, 23 Apr 2020 17:54:25 +0200 (CEST) Date: Thu, 23 Apr 2020 17:54:25 +0200 From: Peter Zijlstra To: Alexandre Chartre Cc: jpoimboe@redhat.com, linux-kernel@vger.kernel.org, jthierry@redhat.com, tglx@linutronix.de, x86@kernel.org, mbenes@suse.cz Subject: Re: [PATCH 3/8] objtool: Rework allocating stack_ops on decode Message-ID: <20200423155425.GW20730@hirez.programming.kicks-ass.net> References: <20200423125013.452964352@infradead.org> <20200423125042.713052240@infradead.org> <7df9ec97-dc14-c4b6-fb26-f163e9afb1cd@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7df9ec97-dc14-c4b6-fb26-f163e9afb1cd@oracle.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2020 at 05:40:38PM +0200, Alexandre Chartre wrote: > > @@ -77,6 +77,17 @@ unsigned long arch_jump_destination(stru > > return insn->offset + insn->len + insn->immediate; > > } > > +#define PUSH_OP(op) \ > > +({ \ > > + list_add_tail(&op->list, ops_list); \ > > + NULL; \ > > +}) > > + > > +#define ADD_OP(op) \ > > + if (!(op = calloc(1, sizeof(*op)))) \ > > + return -1; \ > > + else for (; op; op = PUSH_OP(op)) > > + > > I would better have a function to alloc+add op instead of weird macros, > for example: > > static struct stack_op *add_op(void) > { > struct stack *op; > > op = calloc(1, sizeof(*op)); > if (!op) > return NULL; > list_add_tail(&op->list, ops_list); > } > > Then it requires two more lines when using it but I think the code is much > cleaner and clearer, e.g.: > > op = add_op(); > if (!op) > return -1; > op->src.type = OP_SRC_ADD; > op->src.reg = op_to_cfi_reg[modrm_reg][rex_r]; > op->dest.type = OP_DEST_REG; > op->dest.reg = CFI_SP; The 'problem' which this is that it doesn't NULL op again, so any later use will do 'funny' things instead of crashing sensibly. Also, I'm mightly lazy, I don't like endlessly repeating the same things.