From patchwork Sun Apr 28 14:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13646055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F055FC4345F for ; Sun, 28 Apr 2024 14:26:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1516B6B007B; Sun, 28 Apr 2024 10:26:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 102846B0083; Sun, 28 Apr 2024 10:26:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F335D6B0085; Sun, 28 Apr 2024 10:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D6C426B007B for ; Sun, 28 Apr 2024 10:26:55 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 49895C14B6 for ; Sun, 28 Apr 2024 14:26:55 +0000 (UTC) X-FDA: 82059167190.24.FC002B3 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf02.hostedemail.com (Postfix) with ESMTP id 681D980010 for ; Sun, 28 Apr 2024 14:26:53 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=nLCvQSDF; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf02.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.208.42 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714314413; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=2fUsYUPa7vCU9Uvl/q8HyFhJTUlH3/eY1Gab40DRDR8=; b=6NGO6Q/lWp09qYEpxe0RUs4M4DHxHUx53EWQ1D40YNIpDNWt0jvKJNaTPI4Nx4u6uK76ky 8/4KOfvHRaT1OjKd85RtsJYp+SOQUAEpbFczcM/qsTsMhcz0x6jbGNVzaeMtINkTjVMJw9 u8mVFQdJeHKxFo+h1m5FALiotIt+/es= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714314413; a=rsa-sha256; cv=none; b=N26mm/xQCZ5vgA02m5nmxuBczmYlPVbO0+ikUie5Bf5r5puwwoN6EnKh2iFKFX02VCskk8 ZEU9eamA9nxfxJGuDcT0v5l9NI8h+4UWPmr1Yhx3j6UtLXiS0nSi0XRtEqH+fLm2DQrJ9m JPG6lhEjgl6SvEZAOupFuCLoZVLn4O8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=nLCvQSDF; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf02.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.208.42 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-57255e89facso2536502a12.2 for ; Sun, 28 Apr 2024 07:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714314409; x=1714919209; darn=kvack.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=2fUsYUPa7vCU9Uvl/q8HyFhJTUlH3/eY1Gab40DRDR8=; b=nLCvQSDFu/GYpe1ZOAfMR3yWETMBPYLbH1le0M8BkUy9fZkYAzcn2plIWPKR65yhZt +XK3EUufs9ODj+47m/JOtz8cLEbnBFPLuVo2QrKLINfaeh0AeCIZDyCxhUvlFVHhY7RO gh8IN6A8bhQNVl9EGhZsTcqjEjFDvnB7m9NOUB+bS7lcJonVUZRGCn2nDOi/s0a+ist1 /YjigxmcwBlHxPL2vin0VQ1ew3xPq7EiyJJM6CBiYdpboitps5RYncJaVIMgGDMOOBDo XXVN7biszqiS9zNsaDCeyXvHnTNQbk+zQzQf7idnDaF9nRyO+e9EcXVp+ag7byQJ0hKJ /9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714314409; x=1714919209; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2fUsYUPa7vCU9Uvl/q8HyFhJTUlH3/eY1Gab40DRDR8=; b=kf5LfGzYJuwQZZEIXPFonRaeNNAzJ6tq7I4E0FQvTS6aGLegURmqMwmQQYSdj9LMHa c40KsVRql4wn2GNMFEj6OO+9gVV8T10rVBYcML52tcjGggBb2weC3SrFypc0y3qde5QC fREyKX6LPhmLgXAwL9v+oz1rsMGXDEujWA6gvZbjQsiExec+O9QLQsXyd8lQOPauQBlN alJK1sQd++QY8XX+ealHlidsnH7a9bRAplFaiyJIY942woy5ioPT7Tdu/JVRtF4kPxt1 YJuGa3i264uit7HvHPy35+AFZlkO3wq3yuxiPDUo2XD+TuG/VRsIMXESTd1/EML8wOLw 5tPA== X-Forwarded-Encrypted: i=1; AJvYcCVepturc4U8d3evlFmWFuGju6308KIesfepI3w6v5/CFJaP15R+GFoqB5JUN/oJPJpviIKsQHczBOU6UnWaaG4r4zk= X-Gm-Message-State: AOJu0YwWFotDP2NRzjX1d33MNHVpLmG4oNFndKg/E4j9/hKjxpKwIlKh IGIFqghEcb6TELyNAld04BWCmxkBwe6QANzPzXGHSXWGX0DM28pUC8xdNifqSVs= X-Google-Smtp-Source: AGHT+IFazvolqLNqHW7sn87qc7FNWmc0vAovKyKfUdTKrlrO2gC2bQ/IKjcBl/MzMLcJjyBDHznzxQ== X-Received: by 2002:a17:906:5d1:b0:a52:5460:a1c6 with SMTP id t17-20020a17090605d100b00a525460a1c6mr3656668ejt.48.1714314409431; Sun, 28 Apr 2024 07:26:49 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id r14-20020a170906280e00b00a58e5572f7dsm1916095ejc.77.2024.04.28.07.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 07:26:48 -0700 (PDT) Date: Sun, 28 Apr 2024 17:26:44 +0300 From: Dan Carpenter To: Christoph Lameter , Peter Zijlstra Cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] mm/slab: make __free(kfree) accept error pointers Message-ID: <285fee25-b447-47a1-9e00-3deb8f9af53e@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 681D980010 X-Stat-Signature: dsf7xazc8xtwn5hhgea5sqs8jawxpzfo X-Rspam-User: X-HE-Tag: 1714314413-687657 X-HE-Meta: U2FsdGVkX187/rwm2FJuo/cxQMt67Dl9ng/xWm34/mgsm/nZjUqpBaM7fPksH5cZhrLcDUvC3iDGp5GFUEwwf4irOvD4AuJnIreQNkM3PZ1fUt/hEXEfQpjohbjcxREmUNw+Yq3eRroURYjWPNyA+moYDuDhuGD3s5xjhzsyuTSnZz2IMmwVqP4elJpEnyIDg7y/7fO6izIhViwrC/wjRK/RFNSGhRe7c1kHBZVKTMnJ5nKVtyviVSOLlktQXkb+vy8enrpLTDBJpK35BO33uxH8rhTkL4nk0YMkPVx/1UAG2NNpQ34REXCTsKMYRvbiD+G6cxpzBaqmtTfWyTdgmID68fZUccrcKuTs1RAhhRFvloWHJ+3b0NW4uczy/I4l53kJN5Lba0AVuqCBBalZUuVxB/MS3H0oBGT6KBTpyoUFs8LqApIZSdXAS04uFsgN3h0B5ni86E5zhnVE+p2DvwV82dAfEu63OZg+/xl/pMpfrl12CURKQg15zgo0RqXNAfXnW3IRySWZ7kJoaiFdkOsMc+jlb+5I2LPfWPSt82BBE1SuZy8piDQakME0PLLk6nsm8Z+HrJ/q/MRqJXZxj+0rT3ISfeva3E+23O/C/hurlrBrCBxZ96YQQtSd69XgofFrlN0AQ+fNcf5U34HU9O77WdTKxnzopPL2ktAREZU1njylNMVLQm0DcXmxf937ioprXcxT2sS+tctSae+VSQoS93f6OXDNP5mp6n+gUcp6schFNx8pzR0PhsXcVdl03Cc8zBtsli1myY2jlt2LCjDeI07BsWc+8VXHH3OyveQmD/tH9zpNxsQwc6elu8OtVPlvHl2TfxyAkl1CYUfSvgC2dJy+Q8wt84LoPPHp//+ATw+jm/xZTOTXele/AC+guSbrnShxiJufSImef0YDkb5Ad9S5hfI0UVqtUWBSTuom4JzdjRQKc7//tnFlihA/XlaCeW8+CNVskWOYuV3 kWAv8puT rdX80ywz7vecIrugBWwskYf5XzxQTbDW6NWam8xsiJPj0mdc5nDiD4+O3U+wwpMwB+f2G5fG8Ij41+pagxkt8tkSW/6Z3DPAYv9Vu X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Currently, if an automatically freed allocation is an error pointer that will lead to a crash. An example of this is in wm831x_gpio_dbg_show(). 171 char *label __free(kfree) = gpiochip_dup_line_label(chip, i); 172 if (IS_ERR(label)) { 173 dev_err(wm831x->dev, "Failed to duplicate label\n"); 174 continue; 175 } The auto clean up function should check for error pointers as well, otherwise we're going to keep hitting issues like this. Fixes: 54da6a092431 ("locking: Introduce __cleanup() based infrastructure") Cc: Signed-off-by: Dan Carpenter Acked-by: David Rientjes --- Obviously, the fixes tag isn't very fair but it will tell the -stable tools how far to backport this. include/linux/slab.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 4cc37ef22aae..5f5766219375 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -279,7 +279,7 @@ void kfree(const void *objp); void kfree_sensitive(const void *objp); size_t __ksize(const void *objp); -DEFINE_FREE(kfree, void *, if (_T) kfree(_T)) +DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T)) /** * ksize - Report actual allocation size of associated object @@ -808,7 +808,7 @@ extern void *kvrealloc_noprof(const void *p, size_t oldsize, size_t newsize, gfp #define kvrealloc(...) alloc_hooks(kvrealloc_noprof(__VA_ARGS__)) extern void kvfree(const void *addr); -DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T)) +DEFINE_FREE(kvfree, void *, if (!IS_ERR_OR_NULL(_T)) kvfree(_T)) extern void kvfree_sensitive(const void *addr, size_t len);