Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp10524imm; Mon, 14 May 2018 19:53:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpvhCrgEpvTKG8e8gclewj3aVUy9rSqT6Om26i6YHs63p/me96O4jSK5zRAxN5mOY6iQ9MI X-Received: by 2002:a17:902:7209:: with SMTP id ba9-v6mr12692855plb.119.1526352796494; Mon, 14 May 2018 19:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526352796; cv=none; d=google.com; s=arc-20160816; b=fbv1x1kj72IJeW9j3thovnZ1Mnu24LHmE5sZy6i6WGpK95AdeQwRC9Xknru/DZKTd6 2DgRWVK7b2XN0RV/DdzyWgoM1JjHVTYa2YTvCBZjmgPPo2qhkk3ExxIDCOUCLYNvIz1e ZX+aIAhxarWkA4Gz8WrBEzxmQvR4FpYCsUFVY5s3m8/uHFT/4rpGzNAtce0EE+L4GuBa TVQhwygQKZAtjjXGurO9Db7goK1/rU90RR4+Xz5NLhIv0hT+Tek98TS01Gxhji4uEBpj imeML7cSsi+n7eI+r7X/QZngZ463dhOGGY3HSdfyBxRkBtzlNkpQXzRWmLWl8YdrcUs1 V/dQ== 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:from:subject:cc:to:message-id:date :arc-authentication-results; bh=3gr6YpQgViy8qMl3+G4U/j/OElguivGIEvi/KZt0Hos=; b=0oQaVeOY0dDm3at9Bckl/uC9kX6Ia/0ueqwKP/bWkkIy6RO9vhwPCHtoyFGR5hyrYH ynzYbzQ6y0SRYShzkELqQcwhdtL/ZUR0vIrF0L5mGwgdCHeT5t+WqYY+aJEIubfr4gWy GsmUSFuoBZBOCSzZNfWk8aV6d4XXFYqFgwFlh0m8fp/12ocf/f6rUv1jXxxQRVAVuKN/ kT6SZxqau7HaUthbO0Ao7tf91BAxMYYKsP3Yy6hpKsGuq6VKapXtNVgNWn8O/2mUKEUA ht1gFTiasIgJwpbM/TQlO10ja/rZFr8CtNy5r8GmwblOHQpJ21fGiibVTgGBxS5Zczmz RsxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v123-v6si10910780pfc.273.2018.05.14.19.53.02; Mon, 14 May 2018 19:53:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752383AbeEOCwR (ORCPT + 99 others); Mon, 14 May 2018 22:52:17 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:45488 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752089AbeEOCwP (ORCPT ); Mon, 14 May 2018 22:52:15 -0400 Received: from localhost (pool-173-77-163-54.nycmny.fios.verizon.net [173.77.163.54]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id A49FE13E57CDA; Mon, 14 May 2018 19:52:14 -0700 (PDT) Date: Mon, 14 May 2018 22:52:13 -0400 (EDT) Message-Id: <20180514.225213.1789810083198383905.davem@davemloft.net> To: dave@stgolabs.net Cc: akpm@linux-foundation.org, tgraf@suug.ch, herbert@gondor.apana.org.au, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dbueso@suse.de Subject: Re: [PATCH] lib/rhashtable: reorder some inititalization sequences From: David Miller In-Reply-To: <20180514151332.31352-1-dave@stgolabs.net> References: <20180514151332.31352-1-dave@stgolabs.net> X-Mailer: Mew version 6.7 on Emacs 25.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Mon, 14 May 2018 19:52:15 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davidlohr Bueso Date: Mon, 14 May 2018 08:13:32 -0700 > rhashtable_init() allocates memory at the very end of the > call, once everything is setup; with the exception of the > nelems parameter. However, unless the user is doing something > bogus with params for which -EINVAL is returned, memory > allocation is the only operation that can trigger the call > to fail. > > Thus move bucket_table_alloc() up such that we fail back to > the caller asap, instead of doing useless checks. This is > safe as the the table allocation isn't using the halfly > setup 'ht' structure and bucket_table_alloc() call chain only > ends up using the ht->nulls_base member in INIT_RHT_NULLS_HEAD. > > Also move the locking initialization down to the end. > > Signed-off-by: Davidlohr Bueso The user potentially "doing something bogus" is why the most expensive part of the initialization (the memory allocation) is done after everything else is validated. I think it's best to keep things as-is.