From patchwork Tue Jan 28 23:54:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qasim Ijaz X-Patchwork-Id: 13953370 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 6648AC0218A for ; Tue, 28 Jan 2025 23:54:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA2B5280014; Tue, 28 Jan 2025 18:54:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5211280013; Tue, 28 Jan 2025 18:54:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF254280014; Tue, 28 Jan 2025 18:54:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AE34C280013 for ; Tue, 28 Jan 2025 18:54:38 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5750614032C for ; Tue, 28 Jan 2025 23:54:38 +0000 (UTC) X-FDA: 83058517836.12.F41DBA3 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 89AB3140002 for ; Tue, 28 Jan 2025 23:54:36 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Iwn2Btpl; spf=pass (imf26.hostedemail.com: domain of qasdev00@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=qasdev00@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738108476; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=lfLQghIEMa81iynpw/i87X8Hd+p4i5ylHfkGCvLIXwk=; b=i7o6S0r9LnZo6ZJuLOmYLugPMk8ps+4Y0UoBWIIlJrgUbREain01mWcf/Xlmo/nOWN/kAH MoT8lKiQejLSnv688wFHgbF/34HdqGwtzFG1mMjlIouvMkI3KtaJBAnJLAC6KhXbB+EX8f OoMKkt2epbyi7WPMK558++V8WT5TLU8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Iwn2Btpl; spf=pass (imf26.hostedemail.com: domain of qasdev00@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=qasdev00@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738108476; a=rsa-sha256; cv=none; b=qElxdWTMlPr3k3k+BDnWnukaXtGA/Rq3VfG+kv5IHff+FJYrDJPw4S32FfnqQ7SMyY4KTy 0XAjNfOHOX1DElDCcRZPLT09LAeTg3PuK3BZPZLNhnsyqxVzCIQWuM2s4E+9PTLgbzUoKB dkVQBDnoY1NSC+bemMZIP0PZyPN2RqM= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4361dc6322fso42502775e9.3 for ; Tue, 28 Jan 2025 15:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738108475; x=1738713275; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lfLQghIEMa81iynpw/i87X8Hd+p4i5ylHfkGCvLIXwk=; b=Iwn2BtpljEGocQ8cuF6gmeQZbss4GyDDo2Dz6L6fK9YB6O7kNeZ6VqnSgYB2EvwaTm 9LNJSo7Ogj8FLPaJars6lwv2ThGeagkaAwh3uodEl6BFwYAzblHfNRKZ6L+EvqJ/naqF y7AeQDDr4moEC5STRdWc+f2j++07dIJOqB99f2FEAK09vh81HFmY3yqOKkFCTPX+0D9I OhHxPM/ZeDh8NxjoOFhpwDv8bfoMNaMFN2Bh6NnpFtZSni5QtKrXBROt6Kk5SKKBBoGB zsQ1EOfR+pILcnfpCfQ04YgSDbGxqMhDph6tQ8iJlXpLO4Uml0Ga4pZfu0XH2FDpNx6G 9e4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738108475; x=1738713275; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lfLQghIEMa81iynpw/i87X8Hd+p4i5ylHfkGCvLIXwk=; b=Py0T6g1RXjT0CV5im5b/UsDpc4k8NMIcIBzILaZ6t2qFAVYnObOV/1/LsjnW7bsc5y frRwilKY5H5yaAM2MhslU/iG00341twwYtrfi1+YkpyhPZRV36n6qJKR3SF2mhQX6Iv2 Eem0Y42sjtVzKhXG966S1bl1dHkPm9YvlIQ0CA67gtmJUHTiByfdbS+c/bwYlZEisC73 /pT57JE77FEsu8hbpQ+aluTjSKXdCzaocZ0gAjma+VqItl9fGYRhDm96Mvblt3h41xsU zi4GWF1FBup1L9DfZDZpkkmSLcuiHBGFKB8tV9UDW5Bn/4OIstP+qBn48nAGrXoGGaUb KQZw== X-Gm-Message-State: AOJu0YyNhLbuy8EiKdYCgRSMfWEkvoF68dXLKvNdwewVvu7WDAzZGukP ny49TMeVTu15wo54BehWF7mCTP6YBkx903I45cEdA+fFuUaNIoBvTI1RbQ== X-Gm-Gg: ASbGncs5fiUXx+7kzvnQl4YnecFMgVrTbfn0PdMrLVYh5PgA6+AjF978gyxHhNIm7xS 0SCgsl2XyGn3ZfnCHjAWOdA5vuSBa2Yrqi+eZOagRaqrsB3LymcHLXLZWoy9RJzYGUKt1GtdFME KtIMBbsrAIo/BiIn8tasQoaY9cIqHJtG4+27QQXAgj5e3JxzbA4rX4rs94BPjZlaM0KCjzpXKif c2fld4amWXBDcYb9qZYbr6H/45Bh48yDsopPP5sLmwT5iziCGUR64zqtuW8Wfbdr2O1NWogHGpN O2jqCTrnIY2TbD/A X-Google-Smtp-Source: AGHT+IETnlJuTTfqVMZyRCmZuvdViwOgi4XvzhhiPPeS+syrUPrtSla5X9OerMb25NBupoZv7Gj2aw== X-Received: by 2002:a05:600c:a44:b0:436:488f:50a with SMTP id 5b1f17b1804b1-438dc3c877cmr6772235e9.17.1738108474866; Tue, 28 Jan 2025 15:54:34 -0800 (PST) Received: from qasdev.Home ([2a02:c7c:6696:8300:9ffe:4023:cbe7:62eb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438dcc26d05sm2906865e9.12.2025.01.28.15.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 15:54:34 -0800 (PST) From: Qasim Ijaz To: hughd@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/shmem: Fix invalid PTR_ERR(NULL) call in shmem_xattr_handler_set() Date: Tue, 28 Jan 2025 23:54:08 +0000 Message-Id: <20250128235408.11229-1-qasdev00@gmail.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 89AB3140002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ree5ygjdsppfcyz6uj8ompt8iftr7n6x X-HE-Tag: 1738108476-657065 X-HE-Meta: U2FsdGVkX18kiBQD7YVALy5TJ8WwfmC5IcxCyQem5GJvNUJc1cuLhU9rZkBezua7JVS+9RqgbHyrVenSHJlxLhi5+F9Bs14XiafUd6VXlVhk458V+4W+aHiqW1waelKR1SUThaFNX9EeuBRpThvZnd1Awxoqk8c+JSyQIYDDcgtEDZUf6zT5geHnHgXJkjhNhsXw9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5BCuXV362jRzjMgzLuIKMvM6gk0jf2+6CPSz0n1ZlxEsmpa8F4peLTm3MJMfePQ6YmIG2NdC7Wx3JQevcSmnO7xHkqnUGOy2RNlZY7V64j4fMD1frOvklcrT5sUAVWTDSPGzjmzvOz/g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In shmem_xattr_handler_set() if simple_xattr_set() succeeds and the pointer returned is not an error pointer, then old_xattr will be set to NULL in the body of the following if statement: if (!IS_ERR(old_xattr)) Later on shmem_xattr_handler_set() calls: return PTR_ERR(old_xattr); The PTR_ERR macro is used to extract an error code from an error pointer and NULL is not an error pointer, PTR_ERR(NULL) simply results in 0. To improve correctness and readability, refactor the error handling to have an explicit default return value of 0 (success) in "ret". If simple_xattr_set() returns an error pointer, store its error code in "ret". Signed-off-by: Qasim Ijaz --- mm/shmem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 532afd8e049c..3e97c7890aac 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4143,6 +4143,7 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); struct simple_xattr *old_xattr; size_t ispace = 0; + int ret = 0; name = xattr_full_name(handler, name); if (value && sbinfo->max_inodes) { @@ -4158,7 +4156,9 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, } old_xattr = simple_xattr_set(&info->xattrs, name, value, size, flags); - if (!IS_ERR(old_xattr)) { + if (IS_ERR(old_xattr)) { + ret = PTR_ERR(old_xattr); + } else { ispace = 0; if (old_xattr && sbinfo->max_inodes) ispace = simple_xattr_space(old_xattr->name, @@ -4168,12 +4171,13 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, inode_set_ctime_current(inode); inode_inc_iversion(inode); } + if (ispace) { raw_spin_lock(&sbinfo->stat_lock); sbinfo->free_ispace += ispace; raw_spin_unlock(&sbinfo->stat_lock); } - return PTR_ERR(old_xattr); + return ret; } static const struct xattr_handler shmem_security_xattr_handler = {