From patchwork Sat Sep 17 07:14:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 12979085 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 7B708C6FA86 for ; Sat, 17 Sep 2022 07:15:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EB2A8D0002; Sat, 17 Sep 2022 03:15:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89AE78D0001; Sat, 17 Sep 2022 03:15:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 762B68D0002; Sat, 17 Sep 2022 03:15:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 67CA28D0001 for ; Sat, 17 Sep 2022 03:15:31 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3BF36161C6D for ; Sat, 17 Sep 2022 07:15:31 +0000 (UTC) X-FDA: 79920716862.03.BF8516A Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf01.hostedemail.com (Postfix) with ESMTP id E2489400A9 for ; Sat, 17 Sep 2022 07:15:30 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id c24so1763644plo.3 for ; Sat, 17 Sep 2022 00:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=euiEboSX4sdbeq9UmO12nvx8uEAMFtLZgxLVQeziaMM=; b=HlDkWDLtMRywKdOKQmpeW5A+Q5bj6Cui32N7zuzHb17bwiyg2C+8ioFKvjm+7JmTC3 vd60jGNsfAG20BL8ZbC/C/lvToJLVupK3xLf1MlbQrLC5lqiAbX7/IyIhJ/XBhG7vW+S ouMufuuQEenPqxykeiBRlQyGoKUvBBAzSpGOBZ41pWdHESLhg1SCXWd9D2JkRRgPtnDs 5hK7SmWFCqhMbryVHn3I4e6OeI503DLjoLjg0+LFzK+ngelEZFl6vub4PlV8WH0or4vE WEO2ma7CkG2EL6jmEu7SGWDmRRwqLEWuvME+JG56c+6cmXFHeB834x0UJsbFBsKI9K6Z zW2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=euiEboSX4sdbeq9UmO12nvx8uEAMFtLZgxLVQeziaMM=; b=q7t6L7i3GLmJp85BvnrZg/VvcD1Xbo+cAGNaHAuXrJMwrU0it2cBdx2JgYNV1rMVeZ 6gYwDXUrHoaeEFR9hJQssrEfH0IFvpssQP8APgMw35vnj+s83vV6+ScSfRwQ/UR9ZkLk rsjqo47C0nUaPnPeaQaeaQUdpMhqEu1OF7Segz1uC52Kd1IR7WZNFSVHmpEd0Tjd53KB hgxfkGdWS/pGCMgW2mk9wnXWoRs5SIBGOdGKB1Ju2pnDOafCQkMQEPl3JgKNtMY9/JXh eR9TgBrRyNRBMDtGOL7pLWkrfwvEv5XpgMfwIn7OqjPFI9rNA3HDJqDzio2ArG5ON6sW 5sUg== X-Gm-Message-State: ACrzQf1bHmhLlvIGXTNEmgCH/MZOqL6WjvFcG6T3IpXe82RrCraMGDJ1 sPwPrsxabvn4Kb/uIPgWlwY= X-Google-Smtp-Source: AMsMyM7HJcgHweGOWmpLFyDkTHHlATOBWe+dMv9CzetA3a6U53V746dEsWDsUM4gjqiMcMKHuIWEeA== X-Received: by 2002:a17:902:c245:b0:178:3912:f1fe with SMTP id 5-20020a170902c24500b001783912f1femr3491026plg.13.1663398929823; Sat, 17 Sep 2022 00:15:29 -0700 (PDT) Received: from localhost.localdomain (KD027092233113.ppp-bb.dion.ne.jp. [27.92.233.113]) by smtp.gmail.com with ESMTPSA id b6-20020a170902d50600b0016c0c82e85csm16327792plg.75.2022.09.17.00.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 00:15:29 -0700 (PDT) From: Akinobu Mita To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, akinobu.mita@gmail.com, corbet@lwn.net, david@redhat.com, osalvador@suse.de, shuah@kernel.org, Zhao Gongyi , Wei Yongjun , Yicong Yang Subject: [PATCH -v2] lib/notifier-error-inject: fix error when writing errno to debugfs file Date: Sat, 17 Sep 2022 16:14:27 +0900 Message-Id: <20220917071427.28499-1-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663398930; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=euiEboSX4sdbeq9UmO12nvx8uEAMFtLZgxLVQeziaMM=; b=MHcsimBlF536E16ronDBmCxzUklpevoDzoPZqvz8ljvmRxSdMR6iEkG6QYmeaZo/+ILx0p elRYKhr85Z5ggtx9h1gZsyG10mX2I4R7SFQ/P1Nnj4s3xh/7gW5yx6ClqXEMd/pahwn0Xw Em9tMSd6hmzxY1YYyWkfAV4+mSRRz2c= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HlDkWDLt; spf=pass (imf01.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663398930; a=rsa-sha256; cv=none; b=epvGowR0PU6W/bWwm9MPKxF6qPGm4EY/Flu6n7OJTQFxvmGpBk6Hm/Q2a3buqaEfM4U91O N9nlVsOkk/Pdah3XK/uTxj7Lul9ztOa6gxoW0blt906LrCV7mZJOHca96bHCNapo0xe9/O AoVJKfenTmXy6ZipokimnhAzpN32hHc= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E2489400A9 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HlDkWDLt; spf=pass (imf01.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 1syz4rdw7j7wm14b9fkw89iec63zu7ht X-Rspam-User: X-HE-Tag: 1663398930-25174 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: The simple attribute files do not accept a negative value since the commit 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()"), so we can no longer use DEFINE_SIMPLE_ATTRIBUTE() to define a file operations for errno value. Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()") Reported-by: Zhao Gongyi Signed-off-by: Akinobu Mita --- v2: Fix Reported-by line lib/notifier-error-inject.c | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c index 21016b32d313..30ec41f58d53 100644 --- a/lib/notifier-error-inject.c +++ b/lib/notifier-error-inject.c @@ -3,20 +3,44 @@ #include "notifier-error-inject.h" -static int debugfs_errno_set(void *data, u64 val) +static int notifier_err_errno_show(struct seq_file *m, void *data) { - *(int *)data = clamp_t(int, val, -MAX_ERRNO, 0); + int *value = m->private; + + seq_printf(m, "%d\n", *value); + return 0; } -static int debugfs_errno_get(void *data, u64 *val) +static int notifier_err_errno_open(struct inode *inode, struct file *file) { - *val = *(int *)data; - return 0; + return single_open(file, notifier_err_errno_show, inode->i_private); +} + +static ssize_t notifier_err_errno_write(struct file *file, const char __user *ubuf, size_t len, + loff_t *offp) +{ + struct seq_file *m = file->private_data; + int *value = m->private; + int ret; + + ret = kstrtoint_from_user(ubuf, len, 0, value); + if (ret) + return ret; + + *value = clamp(*value, -MAX_ERRNO, 0); + + return len; } -DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set, - "%lld\n"); +static const struct file_operations fops_errno = { + .owner = THIS_MODULE, + .open = notifier_err_errno_open, + .read = seq_read, + .write = notifier_err_errno_write, + .llseek = seq_lseek, + .release = single_release, +}; static struct dentry *debugfs_create_errno(const char *name, umode_t mode, struct dentry *parent, int *value)