From patchwork Sat Dec 2 21:22:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 172880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1960478vqy; Sat, 2 Dec 2023 13:23:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXADWb2fZkXXZpAGfiK7FwkaaESnEFtqkJCPbZZr80femHCrFIl6+uexlgr/IdC932L1mI X-Received: by 2002:a17:90a:bb84:b0:286:6cc1:292 with SMTP id v4-20020a17090abb8400b002866cc10292mr340496pjr.93.1701552187484; Sat, 02 Dec 2023 13:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552187; cv=none; d=google.com; s=arc-20160816; b=Fj05Fwi1Q7Db9zvS9R+gPRq4LO+8jlLQEjXrf+Jn3utTz8cvowhN7XO95liwQzSGFb 6Kj7TzkONG+ZayV9uOgo+DZjRjvg61bobETHf1hzN2OvN/2nvsjl733ME3bUrJfU9ZHW nC+UwQbeOaM+APjXs74JTteHT8vh7HvtXU5wTwKyaz9BlOZct82vSXuyweES5KXGuHWZ Td2BUqIiod2fMUL/DrydJ8+ErwuKVkPA/xWjWJccOlLyinswQK0bGoVX4P49Ek2+caQo f4yFKie8qW09JFlqJLtfukQj3vCrXtypEXS7vaBu32IMw2P/ECqF273NIljPH81acYLX 9Eug== 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=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; fh=xnUE171Vllx0fx6ipOnwMghUt6fK18sSaxZfCDNQyQ4=; b=rnofC2oAPpxqGW/qZLi5/WBO3AEfLMLT+TUHa5/U9EKheb85Qls8LZveICL52XJ/Tp VU4PyLFlp5hD1knisI8ttwNgGbp/QoPsAyQA44oA7BmE4yDxPwX5dK5t6xhJemzwOzBc h+4iow/SJyfO598V6JGVvq/t6iYXqSU9DeRI14uFtdE6OiD90guOcYF61rxdFIdbQhMl frRn9+WhdIHbydx7+lmNsjVII2WaRZG/hsT1AsF/3S/EWQZig7AV0npE/U/5wHPfpiWw 6TGgOuYmHrmxvvaH6IE97+/y+DFnfNJwTQJCi72SYpAbPbLl9U32DEVDwUuJhrfKcNNz vdDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gr2teot2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h6-20020a17090ac38600b00286864c9cd6si603640pjt.47.2023.12.02.13.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:23:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gr2teot2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B5BC68069F0E; Sat, 2 Dec 2023 13:22:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbjLBVWW (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231499AbjLBVWR (ORCPT ); Sat, 2 Dec 2023 16:22:17 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EAB185 for ; Sat, 2 Dec 2023 13:22:22 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6d8750718adso857622a34.0 for ; Sat, 02 Dec 2023 13:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552142; x=1702156942; darn=vger.kernel.org; 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=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; b=gr2teot24exISStimGuA6uwZHfe8C8GO9of9Yown0wbJwWfmsXN0HEm+HMYnJHXR0K 9BPA7IobVYUOiNHw64fjIRcAzthG9Yf1rAUaizoN6bbILac2nvdeQFcPYTv/SDRcrsMc aFZviUgx0jG0xlgyeAFQpuaji9Z8HASRtWgFY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552142; x=1702156942; 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=Gj+Y/6VXeJ+r0pgecRkRsTt5zcHlqOxutguYUyMKTVU=; b=EoQd9olEzaoVLGsKw7FOpT4dBXkHjJu/Uqpb9CXNBflEWmOSlXoYy9xejbODMatSkG fYQSjvs7HUPepiq+lZcPgqBZzioOVFGrLqg2zpGlHWAXOjK4mfWRC614JiiuANqf2T19 xnMryRaEIopMYcPSbJL5/nye5JwxxFUjBrgRepwX3vj9H9N+eztjF31WLPJkQdVdXlTp KD7G08bZn/6rltFTQZvGR29pN6guQz56iwsnEm6KN8Q6ANU0b7PAPnq0sxTmQKLMRhN8 7r1qhhfuWROHK+gP8tbiVME/6hIujQc1C3HnFXrKAUT50slAkfzRviah67k77PygHupx NSHw== X-Gm-Message-State: AOJu0Yy8PN7KgyD4jXtlYXxaNkgXRQnzGha0VF8Ts/8TB0V6JJ97pLrL GnGFexaNpeiobn7R5S9S+cACxw== X-Received: by 2002:a05:6808:309c:b0:3b8:b063:6b8d with SMTP id bl28-20020a056808309c00b003b8b0636b8dmr1923224oib.60.1701552142290; Sat, 02 Dec 2023 13:22:22 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id p10-20020a17090a930a00b002867594de40sm1351802pjo.14.2023.12.02.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:18 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Tony Luck , linux-hardening@vger.kernel.org, Christian Brauner , "Peter Zijlstra (Intel)" , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/5] pstore: inode: Convert kfree() usage to __free(kfree) Date: Sat, 2 Dec 2023 13:22:11 -0800 Message-Id: <20231202212217.243710-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1508; i=keescook@chromium.org; h=from:subject; bh=FqMfSJ9tnf+E4NKsMDABD4Hv9XWcLEDAeeuD1HVeW1g=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGUcAUjxMoJ6U4X0vLxi+fYt1AWVqAhC5g3 8R9qQmTZrCJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A JqoTD/sEQ48wmQkFhwAOp4TsKfq+vZmWkT5yfGDyxOQ2ucZIBmBzGRljVmzMiuznpXr3hR6RMn6 CI5L7iPa+hQEPuuIdH4ULzOkZKlNGhNWGY6qT/NysWagTanA2+tPygJoTDa3shFPV8Qg/ktXOmA EzaYBnYM32d95qHxY+O7UzeQQHZ+L8mW0w+7Pi4LnpbaEdoxc66d/yrcVqkNxC51p/VeozU/deM rk5C2MNd7/VwWxOqHlp1SIiA899X4IXHIaMopuLi/lfj5TGjWQYSw89mtkk3p/zmCoxe0za6uqJ 5EkmLzOEZ5XC2P4LS/bWhBwNEzOv4Jy7tDzYhbi37IkEM5XnLTEoVRCAB66Swzv/2WOGDhqh3rK IWicrRHiv496Kk7nhiqTyyIQ7vTvoRxCEcarCa+abBlzBe1hcVZa3QWkzGBJyXCYxo8Eqh+vspr 9GNiGEtp4IHwd4bDA7xIm+m36TXHvQTk31FKlch+AdsiZpHPZwxRZ7uslC2pmtV8uCcqoa+MEOQ HeLGQpB9Lheyc3q0B2RPlcqX4RCXu1MzGSJV446zBw7SUb5C/OD4rMGYlzWCHvuMwBVo9ScPTLY Yvnc9q7XkjLRd9JF0+Bf3QSnvRXDIn8bk1Sv2zb2M11q84weUwdkEaxXXSh3/8kBccf3Vc0s6fO bwrQdBKoi0BSe6w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784206786688521570 X-GMAIL-MSGID: 1784206786688521570 Mostly as an example to myself, replace a simple allocation pattern with the automatic kfree cleanup features now exposed by cleanup.h. Cc: "Guilherme G. Piccoli" Cc: Tony Luck Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- fs/pstore/inode.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index d41c20d1b5e8..20f3452c8196 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "internal.h" @@ -64,7 +65,7 @@ static void free_pstore_private(struct pstore_private *private) static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) { struct pstore_private *ps = s->private; - struct pstore_ftrace_seq_data *data; + struct pstore_ftrace_seq_data *data __free(kfree) = NULL; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) @@ -72,13 +73,10 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) data->off = ps->total_size % REC_SIZE; data->off += *pos * REC_SIZE; - if (data->off + REC_SIZE > ps->total_size) { - kfree(data); + if (data->off + REC_SIZE > ps->total_size) return NULL; - } - - return data; + return_ptr(data); } static void pstore_ftrace_seq_stop(struct seq_file *s, void *v) From patchwork Sat Dec 2 21:22:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 172878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1960415vqy; Sat, 2 Dec 2023 13:22:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAWpUUygS4tucwiGh4t33KXY7/J7xo08V4TV+Ve/8hrAGlYkWSFDoA4KphNiWGqBNyGtRe X-Received: by 2002:a05:6a00:1da9:b0:6ce:4553:6171 with SMTP id z41-20020a056a001da900b006ce45536171mr107523pfw.2.1701552175307; Sat, 02 Dec 2023 13:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552175; cv=none; d=google.com; s=arc-20160816; b=ziQjdgxx0hQXgnoIUFtg+iMv1GWfSfnv+YuR/oyhTpYx0rbkftdvzWcjzyK40hawFX AI23fJEHJAc10rzC6kD7iDOWJ+3QLh+LwT81DO2vtYhGUWRfHiDRhguxvgqnHsVaoGZt CdzPjQZ+amjnOO+Qj0W+sf8fEIMzjoK9tJfgV5Bsva5nLMvz/E1+YmJR/16RhBsNQt6O dyLQweTM0X9Q4HmbX67qseOGD3bdqYur6J7gWo7VwyTXaN8FiJX2rUNvsMiR6GBhGCME WwIBjOyAsw5/4+OnflJqQRWXa7S8gfAmTLQidtIN2/rPfeqX4aBtSz7UpMxNseLAQ/Pb V9Bw== 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=K2E08Wp0PAEeNbIbiRL8xBMi7hvEIIZj0Of8hDuuB3w=; fh=xnUE171Vllx0fx6ipOnwMghUt6fK18sSaxZfCDNQyQ4=; b=OarQtmk3YfHJWd/JmyEvy1MNfoX1XZ6ndEG1xjDJ5BQ6lR5z0XPN6+CWb8ulAGZJN2 R0QZ6gW58nCpqXx3OPYEwZfb5UE3LJW5yY6MyHip/INeHw/7dYFXw7nR1hpjJwtjRzLj pk8styzjPBFoYbQxKV1V26PrMFqFHXlLYjPxVeVNpVj6gylzATn+U6PSPfEybOgmkAUG KW1KHY51IdWBajPiGaWf3IBbuKwn2hv9azlJe54j3CIb6tSD9bSmm24rjfSRl1EGDSND A7d1DpehQqQVyhLaK4lWb+7RSXc13fxvoE5nWdqau0ysTMJ79PpCqM7FXwoPVrCdeUdJ wl4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=e3jNmR61; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id r6-20020aa78446000000b006cd8cde4560si5298433pfn.134.2023.12.02.13.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=e3jNmR61; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id C2D23807C5C0; Sat, 2 Dec 2023 13:22:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbjLBVW0 (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231690AbjLBVWS (ORCPT ); Sat, 2 Dec 2023 16:22:18 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A99188 for ; Sat, 2 Dec 2023 13:22:23 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ce3534bf44so341503b3a.1 for ; Sat, 02 Dec 2023 13:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552143; x=1702156943; darn=vger.kernel.org; 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=K2E08Wp0PAEeNbIbiRL8xBMi7hvEIIZj0Of8hDuuB3w=; b=e3jNmR613paODAYSh88L9xEM1dImp1Y1d4fMXxu7hLE96OH4/DxiuFv5TFirICroY0 9IEtMZEoSQvevDOT1SxS0njT9bMRpIYNJczQL34VJUKG7O+VnAIYKEFcWC5l5n/tDAt0 1I4i22JWnCJ+Uq/U9Czv8sTDNmpFIJ9m9OGoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552143; x=1702156943; 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=K2E08Wp0PAEeNbIbiRL8xBMi7hvEIIZj0Of8hDuuB3w=; b=BsiG7kG7q8mbJAAGWvxz5JChyngs+BpQEp2pntt5hivhGy2Yy/GF/Gxok5PTyS6frG SwbeLE0MsEv28AubqEkeiBwh5eTWK3K9Tk7+3bG+cYokxjJGM1X6qH7mwq/NrxTJnmV9 1ek3fjtj2MMeMJ56ukjgl3mgMtZ+/fYFXtJuFf01Sbb4KUFnRXluOHFGTMLWMyWScf53 zcF55GRbSkJ8f/lJWVluFXxNDcVtu+4Q4ppWBEgm2JkKgmy1PbiLAwJn2RsX2SHdUd1m FUgjvgBGCP2X62JAjxJtBkNODyIcWIvScCSghxJe54xq4j4/liD37Oj/x0/fJ71sR3t4 c5ww== X-Gm-Message-State: AOJu0Ywa49widsY+7JnuDbdBLyUy9f+5wH/065ey8kwLPJfLj6Z1xjg4 3aP7wAe4dnWadaRPBXK2uyi1HQ== X-Received: by 2002:a05:6a20:8427:b0:18a:e4ed:cc41 with SMTP id c39-20020a056a20842700b0018ae4edcc41mr2235604pzd.23.1701552143416; Sat, 02 Dec 2023 13:22:23 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id h18-20020a056a00219200b006cdd82337bcsm398007pfi.207.2023.12.02.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:18 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Tony Luck , linux-hardening@vger.kernel.org, Christian Brauner , "Peter Zijlstra (Intel)" , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/5] pstore: inode: Convert mutex usage to guard(mutex) Date: Sat, 2 Dec 2023 13:22:12 -0800 Message-Id: <20231202212217.243710-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4977; i=keescook@chromium.org; h=from:subject; bh=I6QANnpHLWcA4i3gT5wmHz8vdSJtJ/8W9NRntgr7o9Q=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGe1kl5grDFz02MlwEMZbNkkvJk+E/REGw8 MmUW++dTRaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A JnVZD/0UHs7QQfhB4ny79i1LX6AIB3t/4fS9e8+i2EAXHtqKM/YB5Q/5MNIUITrQoyUbCa0qP6Z VKlNoZ/6xCOgH8io2/ZSdrrJ2NpdxAaf5+F4NjBdgTBwZr77g1gzTf2/JdDVcCK9WGk/3Nu8NW8 vEd16nBhaCwVS3t6PhXUgZQNJ/03uiXrSrcVrv6tiLZ5SR722H9vozHpZay7NyLQS4W+obF3i7H xMmN5s8bZVPDrfY0lhPdVrlP5ECSYWdS4ZpfRGf2TzWzOFehtrsIJ9t+SYHxxVqtMMsJl6wobW5 RRQKp0uvQbN1/5U6JmTIiOpthVu8tWgnBgVVG7O3JLsDo8AyFFfqCTZYIUB0k4HAO9wff0kmA1P KOuPovXn43Wl0jimp/DlMzDSUOmj6a9B2PwoWD8ILBmLB2VTky/Lc0AFlqTE2ggkpdhm2vFtGfB GSc8k285KXlWH2rJkCP+R9m6mbnWk8imsHwdrJ6EEhbI/pGs+7QDqTg/5SXEcYNyWHIsbX+QWJS 0Pwm0uUDlv5M3Qe82I7evHxp7ApQb9xzv69YXLfcKD6JQJFO21yMBZFoIJdtBeS1LZkeuJuobZa L0FF1MDhDNL8HlysbWdEFBIfpKoW5rjPXAA9ISnU03BWvMbcQjlu7gadJaOvb4eBfRpa4p/Xm7y LKT/rW6jE9s3J9w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784206774049039141 X-GMAIL-MSGID: 1784206774049039141 Replace open-coded mutex handling with cleanup.h guard(mutex) and scoped_guard(mutex, ...). Cc: "Guilherme G. Piccoli" Cc: Tony Luck Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- fs/pstore/inode.c | 76 +++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 20f3452c8196..0d89e0014b6f 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -180,25 +180,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) { struct pstore_private *p = d_inode(dentry)->i_private; struct pstore_record *record = p->record; - int rc = 0; if (!record->psi->erase) return -EPERM; /* Make sure we can't race while removing this file. */ - mutex_lock(&records_list_lock); - if (!list_empty(&p->list)) - list_del_init(&p->list); - else - rc = -ENOENT; - p->dentry = NULL; - mutex_unlock(&records_list_lock); - if (rc) - return rc; - - mutex_lock(&record->psi->read_mutex); - record->psi->erase(record); - mutex_unlock(&record->psi->read_mutex); + scoped_guard(mutex, &records_list_lock) { + if (!list_empty(&p->list)) + list_del_init(&p->list); + else + return -ENOENT; + p->dentry = NULL; + } + + scoped_guard(mutex, &record->psi->read_mutex) + record->psi->erase(record); return simple_unlink(dir, dentry); } @@ -290,19 +286,16 @@ static struct dentry *psinfo_lock_root(void) { struct dentry *root; - mutex_lock(&pstore_sb_lock); + guard(mutex)(&pstore_sb_lock); /* * Having no backend is fine -- no records appear. * Not being mounted is fine -- nothing to do. */ - if (!psinfo || !pstore_sb) { - mutex_unlock(&pstore_sb_lock); + if (!psinfo || !pstore_sb) return NULL; - } root = pstore_sb->s_root; inode_lock(d_inode(root)); - mutex_unlock(&pstore_sb_lock); return root; } @@ -317,19 +310,19 @@ int pstore_put_backend_records(struct pstore_info *psi) if (!root) return 0; - mutex_lock(&records_list_lock); - list_for_each_entry_safe(pos, tmp, &records_list, list) { - if (pos->record->psi == psi) { - list_del_init(&pos->list); - rc = simple_unlink(d_inode(root), pos->dentry); - if (WARN_ON(rc)) - break; - d_drop(pos->dentry); - dput(pos->dentry); - pos->dentry = NULL; + scoped_guard(mutex, &records_list_lock) { + list_for_each_entry_safe(pos, tmp, &records_list, list) { + if (pos->record->psi == psi) { + list_del_init(&pos->list); + rc = simple_unlink(d_inode(root), pos->dentry); + if (WARN_ON(rc)) + break; + d_drop(pos->dentry); + dput(pos->dentry); + pos->dentry = NULL; + } } } - mutex_unlock(&records_list_lock); inode_unlock(d_inode(root)); @@ -353,20 +346,20 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) if (WARN_ON(!inode_is_locked(d_inode(root)))) return -EINVAL; - rc = -EEXIST; + guard(mutex)(&records_list_lock); + /* Skip records that are already present in the filesystem. */ - mutex_lock(&records_list_lock); list_for_each_entry(pos, &records_list, list) { if (pos->record->type == record->type && pos->record->id == record->id && pos->record->psi == record->psi) - goto fail; + return -EEXIST; } rc = -ENOMEM; inode = pstore_get_inode(root->d_sb); if (!inode) - goto fail; + return -ENOMEM; inode->i_mode = S_IFREG | 0444; inode->i_fop = &pstore_file_operations; scnprintf(name, sizeof(name), "%s-%s-%llu%s", @@ -394,7 +387,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) d_add(dentry, inode); list_add(&private->list, &records_list); - mutex_unlock(&records_list_lock); return 0; @@ -402,8 +394,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) free_pstore_private(private); fail_inode: iput(inode); -fail: - mutex_unlock(&records_list_lock); return rc; } @@ -449,9 +439,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) if (!sb->s_root) return -ENOMEM; - mutex_lock(&pstore_sb_lock); - pstore_sb = sb; - mutex_unlock(&pstore_sb_lock); + scoped_guard(mutex, &pstore_sb_lock) + pstore_sb = sb; pstore_get_records(0); @@ -466,17 +455,14 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type, static void pstore_kill_sb(struct super_block *sb) { - mutex_lock(&pstore_sb_lock); + guard(mutex)(&pstore_sb_lock); WARN_ON(pstore_sb && pstore_sb != sb); kill_litter_super(sb); pstore_sb = NULL; - mutex_lock(&records_list_lock); + guard(mutex)(&records_list_lock); INIT_LIST_HEAD(&records_list); - mutex_unlock(&records_list_lock); - - mutex_unlock(&pstore_sb_lock); } static struct file_system_type pstore_fs_type = { From patchwork Sat Dec 2 21:22:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 172879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1960471vqy; Sat, 2 Dec 2023 13:23:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnR2Buduf8xRYWU2WlmmA7++rnBwxXPRfqUCTvWM6qutX46vp/A8kHv9qhRDUwc2zhGN7j X-Received: by 2002:a05:6602:2c4a:b0:7b4:28f8:1e01 with SMTP id x10-20020a0566022c4a00b007b428f81e01mr2972825iov.32.1701552185946; Sat, 02 Dec 2023 13:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552185; cv=none; d=google.com; s=arc-20160816; b=a++9aaSyDLdYu2WLXg1GZKKZ+e4Zw+Egvm36ijhqeiTBJwtLguaM95KFbEpwhsf+D2 1pE+gpOUPF15PKyWYRhSMhXDi86AWqBCgYGoVUJ8aivxoJ1d0Yp3zBzlBH3Dbw0zP74b A6XznNb0sVIzG5wcOzcvPLW5fdBMIGAOT7fRy10XnGRvjMPl+KzA4FF/4FACX0rW/phf KcNA7CnSHqaNYSFKNP/xhBuX+1Q8Y1UR0neBW4oxlhIt3r1Fvd0HIOWNiXoy7YvPCegS W6BmRM3iaSBOSH2ht5xPjjA6wayUFoqvY4aGFPWYvG2IAJ+0G+Ma6XjHN+k4cdlO37QI 3xwQ== 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=aLvxvckvyomlZOIIg4Wjwswvgj0BL428CVO+nAzlFtE=; fh=i7FAZL+gbVc1kTTivPIZXgDzyPOWdZrWVS7ntfVLB30=; b=KzPHO+q2i1UoU+aR5gVKz0zE8obUrSk6UTaF31vEtLUDEAPbFW+ZmKS4X9dSOsk2Pe MziHfgPm286mZ0GzQq9Orj58szWheU/TpaNj/s/NcFqy/h+gM1kmh+nxrpVeN59NbCjC P+T4t0AI9/tbiJNuvFKACouH5dYWT5rOIWtj3pQkkq19T3gprc/NQ25xyHArVppYs4+b PIjqTSM+qW9eOW5NtkedSnSrXEXcn4PwIrTrfp5zvmPRrQZ2S8D8o+6Nsd59KLONsOjo cQ4EWAkGYxS4S7W4ibhADRwcWkhDvar2xEtlseJRp2giy8ixBt64UaxtuvqCcB30bHWo xu9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YA5NcrkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e9-20020a170902b78900b001d00a9256adsi3542413pls.488.2023.12.02.13.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:23:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YA5NcrkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8AC058069D90; Sat, 2 Dec 2023 13:22:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbjLBVWS (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjLBVWR (ORCPT ); Sat, 2 Dec 2023 16:22:17 -0500 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39CA13A for ; Sat, 2 Dec 2023 13:22:21 -0800 (PST) Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7b06841efdcso123444439f.2 for ; Sat, 02 Dec 2023 13:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552141; x=1702156941; darn=vger.kernel.org; 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=aLvxvckvyomlZOIIg4Wjwswvgj0BL428CVO+nAzlFtE=; b=YA5NcrkM5udEWaHHh2G+rmz62ChxvRvmbuIaxK6S0HmU0dsnoYprOaEiaJ+Bbj/pE0 X8/WCK0HfL43CDLXxWRUeqCFrVa9Xk5RwQEO79zs3ktain0CD+LqjL6cCUM3uEcRVFcX ADZbHiYgQnmAcZWmNncFbgqi6QMwCHkKl+XgY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552141; x=1702156941; 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=aLvxvckvyomlZOIIg4Wjwswvgj0BL428CVO+nAzlFtE=; b=nfVGD7+CG1Rfz5C07NCWpYRcZ75FcJ2v7qP90H09+RIh0bHbo5jsgnNzx6eWYTX6AG c4UwATf2hsmODbwzm6ks96UufeWx4lwJ3eQIP3vZ1xge1k10lUwXIVUS/9+hxrfvznKs 9CoHNNXusPcUaq0lRQ2xKOTALh+xsuReTuDJuXvgeouNxhdl+SyXE+K8zTATyyh71xN1 x3BCgb5kxYfJm2u6i05E5L2ys62TZR9wx84yvd9HTkf5N40aBTeeH3ycOPHjTsMmSMgG fyDzV3vlXrCXz8spf6TEWvCPiNK1MYuksoZmFZaRmr4WOWY5815PV2qsZoNSxGy5rIeE tRCA== X-Gm-Message-State: AOJu0YxQwHDCMlhCBbmkxumQzy7f/98shMbd2wQWookyjOEUrEZQal/y eLycX8w9nwLx9P3WJmTM4jPe0A== X-Received: by 2002:a5d:894b:0:b0:7b3:9256:628f with SMTP id b11-20020a5d894b000000b007b39256628fmr2310006iot.15.1701552141318; Sat, 02 Dec 2023 13:22:21 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id j6-20020a170902c3c600b001cfd049528esm348997plj.110.2023.12.02.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:18 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Christian Brauner , Peter Zijlstra , Alexander Viro , linux-fsdevel@vger.kernel.org, Tony Luck , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 3/5] fs: Add DEFINE_FREE for struct inode Date: Sat, 2 Dec 2023 13:22:13 -0800 Message-Id: <20231202212217.243710-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=835; i=keescook@chromium.org; h=from:subject; bh=Vr7BZE93w9hrA2pgUGte2wnKY/rdltDnNWxbve4aQVs=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGSav5RcGFsYqI8ZI6gPChQFnsbC+3nI/Sq AQMSCvSeJuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A Ji1PD/97nsFeEYnRWCY5ijYm3HvFHnw2xsSeLfCgNERlEsvkDTZnVu32g862lrZ6hmNnj1/2WLY q5BTXJyqzwbbUg83+V4Z7IWpauoICvmh5nWCVw+d1swRjKLklznh+kH+lxKH782U5N+1W/bPv70 NdRhJBCPVOIeyBMGaFNtfbgw7Q7/MKTOSU/62VCry3sVE9fgDWP9DnB0W9/AVEf5mttk4aI+XJP Jf0b1606ZtWwo4iih+TPjLRID9WD2cRTVsaeRdH6h2sVpbIWtLfBMYm7MUT4xvIE/X34XC1XbGH /mFyNY6PyZyWNI/tRahhMjKTPtLuV+I51o3tpDU6ScYTIbUYyvn1SktT2ZE2PeBRIK7UUg8Kekf uMNNH7+hll0EcFYUEBOQ4ErCJ6guTCAIxc+68VotsoujHUSgriM/jZWU+UdawDQmyw5w2Zxt2fH io2IkOg0NktS5Lz/oNbESXSgqAIcAsWZYdpz8f5sULzKfDAWY9NZCkKawVLDlwQ3EVVq3ugJ4nO /+MhL408XJIGHI6nAbKY8QyfaPWyUeqbflROQiQEI6UVXEYbPuKogAFFyNGXqSlpZfzWjwQM12w tqybXEWAcWdB/zgRVWCl3j9u393bvwCn78YpxLSABa2mDjF9niWPVYIK3247bi3TGEcoqVKm7/q lL7bpxiJe0Uvk7A== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784206785279767858 X-GMAIL-MSGID: 1784206785279767858 Allow __free(iput) markings for easier cleanup on inode allocations. Cc: Christian Brauner Cc: Peter Zijlstra (Intel) Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kees Cook --- include/linux/fs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 98b7a7a8c42e..7c3eed3dd1bf 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2459,6 +2459,8 @@ extern int current_umask(void); extern void ihold(struct inode * inode); extern void iput(struct inode *); +DEFINE_FREE(iput, struct inode *, if (_T) iput(_T)) + int inode_update_timestamps(struct inode *inode, int flags); int generic_update_time(struct inode *, int); From patchwork Sat Dec 2 21:22:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 172876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1960351vqy; Sat, 2 Dec 2023 13:22:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVmTXneVzR3JHkrsC3NT2Ly4dKCRVQzDl5WTLsaa7mJKbMD+q9Pfcby04WS8nv8dHiz0DG X-Received: by 2002:a17:902:db10:b0:1d0:6ffd:9e19 with SMTP id m16-20020a170902db1000b001d06ffd9e19mr1577873plx.107.1701552162385; Sat, 02 Dec 2023 13:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552162; cv=none; d=google.com; s=arc-20160816; b=UXzY5Xoh0c2xztrcOlaeoYNdQj4X8QGcwmN2E6Y4tPxv+FzUAY8drDFDQVmDKI9imv bsXjWURGt24UYek6epmlSxd7eTinVJpGodLH+7yI4tJJoNh7rNkno1boLrbVaKuBqPny Nx+6AlIPk1GwDhlEI7TRij3X70fkJmpCC++OQ5I7Fkp4rAREsVez15T1A/jREdH0pNIR K55uyTqSe7szGfYD8UoCFX5ktr7/jY1nx6dZWM5POptgZsDobshssNurFM1DXTcg48JN kI4EkJqn3K862bVK7z6qUoyXYrzGMq21Go8QzCNNEZAcU+1AV+ospp2o+8eJ570A/g/V r1kQ== 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=2dZKi9NMCd2PNGrGsX8s5UPrOfKzB/ri42Q6YHImLKk=; fh=xnUE171Vllx0fx6ipOnwMghUt6fK18sSaxZfCDNQyQ4=; b=c88irMi47ei67NcGeNOjTrF/X3sWgnwSexNgTFQXKBCPu4U0rbfxRWCmRH4q67/wS5 rBR+MH63RuKS/7UJEl/NZZswxKUhzkuPosaseJwGIE6X2PdQ9k84vdC5yKCVWHojCaIW B/Y4JWNQFu3onqmh1m7e4wmIBM+Oysu19c4ePytPQDMY56JdmJs2L3ti0iI+UwW+AVZm KHljr2Ejtd/KLLt+pb/aAnOlrt43bOp9rciCHFnJUqH5CeVtM4V00gxVOFHTObngR01h egplJMuphSyxOnYTdSeTLlgFDypZw26RugDpwZE1kpZeQXwPvrUqtuC+cQxRANUXWZAV Ik9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=elr09MWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id w4-20020a17090a8a0400b002639acf55c7si7873018pjn.7.2023.12.02.13.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=elr09MWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A5A6F8087F1C; Sat, 2 Dec 2023 13:22:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231830AbjLBVWU (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbjLBVWR (ORCPT ); Sat, 2 Dec 2023 16:22:17 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F04B125 for ; Sat, 2 Dec 2023 13:22:20 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d048c171d6so16166815ad.1 for ; Sat, 02 Dec 2023 13:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552140; x=1702156940; darn=vger.kernel.org; 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=2dZKi9NMCd2PNGrGsX8s5UPrOfKzB/ri42Q6YHImLKk=; b=elr09MWOGl290voBUBoq7u39jrDe/xO30ixZh0QZYZAORAFEjs89UMRw2WMEGRbvFa /98vrGb1rWz/B/I6YM2/FuEfvvidMrgNoP4f2KPMTvvENFaKwQMrorysQEYSvoY0b//W QpTvfB8ega9RBGbfdj4sdCZ1fQ/Pc6afycvvs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552140; x=1702156940; 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=2dZKi9NMCd2PNGrGsX8s5UPrOfKzB/ri42Q6YHImLKk=; b=XYZthDKYfOFB0RcrpAkcyriWxylPNOY84HmlFmLyj6CLsRuiyC6R0rZbuc+6p0R5Jo wxhpdeniBFnzeMTXB7iVohff2JWAUecE8gVN08i31/iDWWJVRRQonx1g1lt5pJdKmkgW fG+/nsHBq/mP1ocdfW2laA4VgPUxDgFfkicYliws5WL52wuAEueD0I6prUFsqvpLM7tI ELGxZzrZBDbes14JRu1OEIqcBUbQAjlJ2Ewtp+cyrXZA0E3vCHgFnwdFeVd8X87AE/2g 8A7esMFu2hA/CoVunlv/14P8iN8EEwQIsASMXG2UyvijgVq6WQ+8GvCcM6W84AZu4ebN qJIQ== X-Gm-Message-State: AOJu0YzOqHb1tp6eiTpPA9z1WBd46INsu68+vTVVGl6MxhWZWKwjhHZE chZ2VTgNRSR97X0wTTx3K4vyUw== X-Received: by 2002:a17:902:e844:b0:1cf:c3fb:a982 with SMTP id t4-20020a170902e84400b001cfc3fba982mr1644556plg.63.1701552139834; Sat, 02 Dec 2023 13:22:19 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id iz2-20020a170902ef8200b001b9e9edbf43sm261943plb.171.2023.12.02.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:18 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Tony Luck , linux-hardening@vger.kernel.org, Christian Brauner , "Peter Zijlstra (Intel)" , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 4/5] pstore: inode: Use __free(iput) for inode allocations Date: Sat, 2 Dec 2023 13:22:14 -0800 Message-Id: <20231202212217.243710-4-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1577; i=keescook@chromium.org; h=from:subject; bh=LrFJJwbwaP3diV7F4yBd+rDDPSuUzm8XAAzIy+IkY44=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGPooNcpMsUpMnk7AZ7HA4049QAKPudX3SC 5es+XxUF3uJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A Jq24D/0dySbOgDPtHzuco4GLjV8/iYcSa9kl2NxlYzcrytw4fgSpsF8oNM8CLBO/GXJ5Daol0AC Bt8jiWEvGaGCBkZQNHWCIGJGMAtRJyDYsJZSo5rR3SBjHlROGmwejZSlN2jXViiCOqlVt5YpuWR eHbR+BGWN+kRXzxEcpstmju+PVhbOto4kr1BCnJiVPxQA6zonvrcinQGGOXfW4FQrX2/+F0bQLc 53nLZwcp0uDrnn8GDTUT7qZtSGqmQeUZwEtg4evOEM00CZXSJC6DCqntTn2k7+hCKznMz5IiJtE hrTtOUNTs2+FivyzNehv/RqK29xEV9jqkmeo9TLdLQ7N4mTEAb+uV4yKv21mg501odxycBHoamE e0BCS6k6HsaMHaIDM6SrTWfFPgi6o2ns4Uf3FUsQ3/6OTUEnqH+dtWaCnqjZMmJEBMlrg0HtjmQ trCoUfAwQWB9c+MtiAHDLQGqn4uw4bmmTaR1tTY+raBeV5lT60xOjJxBrNpM7zQ5SLLC+FQuOEd zQkKLeHJij3Bufk0646mwUGtWowKcPno5w9lNbO0WEv1cVhI3EoEew402Iu8IJQwWujM/0iBI1v J0eRgwkEoAE8Ed/6YEelW+hrgLvz3ABThVaktG2XO7jnh2Pki7SBtdv7e/MojC5x3QYA33h3xzw or4Uvecyt9Mh/aA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784206760240434665 X-GMAIL-MSGID: 1784206760240434665 Simplify error path for failures where "inode" needs to be freed. Cc: "Guilherme G. Piccoli" Cc: Tony Luck Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- fs/pstore/inode.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 0d89e0014b6f..20a88e34ea7c 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -337,7 +337,7 @@ int pstore_put_backend_records(struct pstore_info *psi) int pstore_mkfile(struct dentry *root, struct pstore_record *record) { struct dentry *dentry; - struct inode *inode; + struct inode *inode __free(iput) = NULL; int rc = 0; char name[PSTORE_NAMELEN]; struct pstore_private *private, *pos; @@ -369,7 +369,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) private = kzalloc(sizeof(*private), GFP_KERNEL); if (!private) - goto fail_inode; + return -ENOMEM; dentry = d_alloc_name(root, name); if (!dentry) @@ -384,7 +384,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) inode_set_mtime_to_ts(inode, inode_set_ctime_to_ts(inode, record->time)); - d_add(dentry, inode); + d_add(dentry, no_free_ptr(inode)); list_add(&private->list, &records_list); @@ -392,8 +392,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) fail_private: free_pstore_private(private); -fail_inode: - iput(inode); return rc; } From patchwork Sat Dec 2 21:22:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 172877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1960398vqy; Sat, 2 Dec 2023 13:22:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMH7pZ+dIS1fF9CEOx3P7SmvLeGwIQhKgAfQ7I063yzjUvyepbFBiD/pHTVLVWKNofIcjn X-Received: by 2002:a05:6a20:7492:b0:189:c46d:9790 with SMTP id p18-20020a056a20749200b00189c46d9790mr2486635pzd.30.1701552169624; Sat, 02 Dec 2023 13:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701552169; cv=none; d=google.com; s=arc-20160816; b=Yk0PIeilsRJOJsjDZSw0MCxaaYez2ICqwmVpJpp+MUvRZcEpTzRoQkUk7EyAKJiBr9 JpQApJA7O95uESRfDn6YLP6t3+XYL9809s35UxREO5mgjmmFVg/eahfVihcvb1MZ3619 8W+NQTX0kuqEYdmC3+NtmwsAT4E02aAgl+HIUx44B1KryPcL2ZExRLO/Qxrq4QSlAjdH 2okMjoxRLyWtB0Nn6DilS0H0bK5YeeMGIrcWA4o2cK1bIVOwUQS6XxHxRruenHKx/fKy VErwTt5Xwc5YAH9O0tp6lvPZ9GIT7g1KVreQ5LYkpmYGT8q1/YuaFzK2cOBngEVZFcIJ Pozg== 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=kr8v5ioi9yhGCNoI15AUxdx1ZJerS/H1pXIO2zt31RE=; fh=xnUE171Vllx0fx6ipOnwMghUt6fK18sSaxZfCDNQyQ4=; b=Mm7Fk6g0GnWxv/G93IkFge7PFeZpNxcohHERjj+14ZGpd5sOKX2fi54YlO5On6Q13I uv5viaH8oBGazmxH33gM8MHhcOzExiylgdug9zXOHnWRAPu2RZ2EtOmYbXAAq1IV7Im0 tcW64Ib6Fy4sY3eFAwVGtM9l4ybwwMmY/vv5Vje4CFqiAIIU34KzrgHNC/4QXmyngI43 K7kacrZtOEFJZ0y/PNd+ihU33nxWuhizJvbD4BHCqGojvuSL7HnOGDGqgI/V7VNVPF6t 5Xc+jwzEaD/GvJH8+2PbM60kCoRDmhPLZEs99Wbl1E6G4pQKE5EutT/bTZUibmdsZp6i TZtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HqKQgTMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y15-20020a63fa0f000000b005c663b4fcc5si1167692pgh.458.2023.12.02.13.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HqKQgTMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B0D79806500D; Sat, 2 Dec 2023 13:22:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbjLBVW3 (ORCPT + 99 others); Sat, 2 Dec 2023 16:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjLBVWT (ORCPT ); Sat, 2 Dec 2023 16:22:19 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323A5196 for ; Sat, 2 Dec 2023 13:22:25 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d0538d9bbcso15662195ad.3 for ; Sat, 02 Dec 2023 13:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701552144; x=1702156944; darn=vger.kernel.org; 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=kr8v5ioi9yhGCNoI15AUxdx1ZJerS/H1pXIO2zt31RE=; b=HqKQgTMBVxs/PT2XUTy4QRahXlfSOpb+2P7T6oLQzKCBFsyL7sId4K0GghvgK21Uv5 H5hmnBcZgSJAEkhxmg+UmVxXMrgpE0bVBwDomQhPXq2/gEX0wmzoCY5h0EdL4M5urKgz uNQvfiQYtnror4SJNB7CNjTQ9HpIyDwmvJ07A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701552144; x=1702156944; 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=kr8v5ioi9yhGCNoI15AUxdx1ZJerS/H1pXIO2zt31RE=; b=BrHE/YOsaG1NFZi75qH80lZoAZi7czM1aO1aAfiErbNUYMhTO9Ukg4bDaQbLNV896H liFmzLcAduJvCWmeGjLQLx3vJdsLHe15y0Qu7CmhONagN7f+ZnDxm1jbGy0nee+QyK3a QspSm4t+ZoETfPmFe4WIfpY9ld99fouNNILbIIOMQFPYF+GEcVblvT4ModxM4h97BYbN 5ZYSlT34j/bYDl8HKgnU+NkX3j9du04wSCpwHhQ68OfTdZ/lOZcwek/7EajfClRhNpqr ac942qIFuUY0VN7etcDzLWhucwYdVbtJZF/BVDJpPqy2gNq8tBuWXig52ZrgZQDsVVf6 vheA== X-Gm-Message-State: AOJu0YyFMrnLz68LSLr8tDNi65d5qeJ6mWtek9nMfTTnMzLbwmSVqwop 2W0XFa7+S3Gc3LJBCZn1hwdAZA== X-Received: by 2002:a17:903:22c5:b0:1d0:6ffd:e2c7 with SMTP id y5-20020a17090322c500b001d06ffde2c7mr2044102plg.97.1701552144686; Sat, 02 Dec 2023 13:22:24 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id m10-20020a170902db0a00b001cfb971edf2sm5607037plx.13.2023.12.02.13.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 13:22:23 -0800 (PST) From: Kees Cook To: "Guilherme G. Piccoli" Cc: Kees Cook , Tony Luck , linux-hardening@vger.kernel.org, Christian Brauner , "Peter Zijlstra (Intel)" , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 5/5] pstore: inode: Use cleanup.h for struct pstore_private Date: Sat, 2 Dec 2023 13:22:15 -0800 Message-Id: <20231202212217.243710-5-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202211535.work.571-kees@kernel.org> References: <20231202211535.work.571-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1987; i=keescook@chromium.org; h=from:subject; bh=2VOJhxKhawry4zB5INkZO9i8H3FTFJSHkB6X8kUlVPU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBla6AGDW8hXonEKigawraWf7F2wiPHsStg+E08f Sxgn4os0kCJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZWugBgAKCRCJcvTf3G3A JhTDEACNiMPD3b67gn9zNW4/ju9hFrGMsJjSQ7KEHIZH8TvkblvRnwZFbrVAPlbHrhqyzPnosiv RrgJmNPJReV/CWU6tQkLFnyPFYc9GKeS0lBBFOcMLGu/XDM9G/Sjv+ZeYTyfyOW6IeluJIuMPBf EJyjm2w/tlZMPldQNw5gwettLVjEjThBz1y/LgIQwtWWgiUzfLyYeApXA1LCey9bZ2OkCUchwgW 0BKcL2Puv1CtHOHwZ/FQ/MyqA2ADGyA4mrpGl7d4toQk4uECTTsv+qOtu/6wKASvbYy4QIJmLWE xkeWVRWohYcqWeUg9DoahE3IcWnA0ry6NNlMLpUtEmhx+U7CqpYXT5ejREJ3h1deBf8Gwivt1de UoDxTsF8u5rZwsrK6livq2nG+q45XPK+SCG6CzZ+bCU4FxSdppDD9d7KyQr1p2YWc8KqZvCSIdK UCZepXh6abHECZC7ZgiPujvwxB3UBFpStBlAeWso5EUm800a0CUyB6/poJiZyAUd6O7/Hh2GOds jnhPwrkBxp+1gXEEjY4QOy+zay5bdrkNrVQ6ZsF5UwBRGPUx0o+WG6TKpWWoILlQ4mJ1YeZMgj3 6c0WQUcvUTwxxJtuLLMynSwKn6uBKeMJRkc+EY51mYXZ4kw+4CricAYkzOAVyvaeCuKucDZCiFH Ngx7gfISAw/fzgA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 02 Dec 2023 13:22:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784206768130110014 X-GMAIL-MSGID: 1784206768130110014 Simplify error path when "private" needs to be freed. Cc: "Guilherme G. Piccoli" Cc: Tony Luck Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- fs/pstore/inode.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 20a88e34ea7c..7d49f0c70dff 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -61,6 +61,7 @@ static void free_pstore_private(struct pstore_private *private) } kfree(private); } +DEFINE_FREE(pstore_private, struct pstore_private *, free_pstore_private(_T)); static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos) { @@ -338,9 +339,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) { struct dentry *dentry; struct inode *inode __free(iput) = NULL; - int rc = 0; char name[PSTORE_NAMELEN]; - struct pstore_private *private, *pos; + struct pstore_private *private __free(pstore_private) = NULL, *pos; size_t size = record->size + record->ecc_notice_size; if (WARN_ON(!inode_is_locked(d_inode(root)))) @@ -356,7 +356,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) return -EEXIST; } - rc = -ENOMEM; inode = pstore_get_inode(root->d_sb); if (!inode) return -ENOMEM; @@ -373,7 +372,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) dentry = d_alloc_name(root, name); if (!dentry) - goto fail_private; + return -ENOMEM; private->dentry = dentry; private->record = record; @@ -386,13 +385,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) d_add(dentry, no_free_ptr(inode)); - list_add(&private->list, &records_list); + list_add(&(no_free_ptr(private))->list, &records_list); return 0; - -fail_private: - free_pstore_private(private); - return rc; } /*