From patchwork Sat Sep 17 07:06:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 12979081 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 69329ECAAD3 for ; Sat, 17 Sep 2022 07:06:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AF8F8D0002; Sat, 17 Sep 2022 03:06:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75E7F8D0001; Sat, 17 Sep 2022 03:06:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 626A48D0002; Sat, 17 Sep 2022 03:06:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 54B238D0001 for ; Sat, 17 Sep 2022 03:06:31 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 23A9D121C8E for ; Sat, 17 Sep 2022 07:06:31 +0000 (UTC) X-FDA: 79920694182.29.F09A79D Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf21.hostedemail.com (Postfix) with ESMTP id D62DB1C00BE for ; Sat, 17 Sep 2022 07:06:30 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id x1so23408840plv.5 for ; Sat, 17 Sep 2022 00:06: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:cc :to:from:from:to:cc:subject:date; bh=gB5h/T33V9gpZKvAPxPSR02YTU84Z6GoD+iIQZO//cY=; b=KH74j79optJm/jPjL8g74slfPsyfsrBezccD6mT1SE1JxPaLQL9PcAasqLT2ogJTnc u2RN+2epzvo6OXn1yrsZ0OMngtA8qiGMVqSuDkDHTUuC5YvZP4gKuZ2z98k0zife6kHS 8R2yoHS4RyNGM6uq3W1HMsBwtggPAJhTXCBS1zx8RxlBCG6/russaXzgnSyBlXK1LSgb RdfwUxlvlMRLhVQ76xHs9cqCDtJh98IbGp241D0iLkFtq+1JDBr58g+0xFVE5Nj3jx9u ku04TBuWF3q/sO6bX22FqtnwsXBTH+2zaaTJRY+WWWHxILKGfLtuCl0SBUptQ6xaqEnp dDFg== 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:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=gB5h/T33V9gpZKvAPxPSR02YTU84Z6GoD+iIQZO//cY=; b=SdE2dsrWAxGuyWMLNOVqM/azQqRVSCgi0Mw03O3lCcu6PhZjZMtAicbt7X84HO1g6L 5vS3n8ctWViEebDrvRMJ3T4wY4DK9KxbhQF/BOx9M/5Uf9JGPlXkCMjCrycbsy1HmM/o oQHekRSfpaqPn834FFd3XG2tC1/Hgp9JU5sAeoYmYwOHadWmhdn6qNfZjyPzDDGCm6lX r43n/RY3D4Uf7M6g2w66b8vBjip45YY6AE3+BJYfxpF3E5NXkKzMNp2A1OLHn70/6Oyf CBZXgEH9tT/nZlc2aGj8pQf5AxaSUMDDfF8G1FfDjqckA2jK3hhh2FJfzvsiXIM/M7EG 9Evg== X-Gm-Message-State: ACrzQf1cPXFcY/gl2t56anJm541rnHYsUypW28o/mnDWjoTp4dAwV7E3 fAshC6FVwZQJdQurs+Yc26Q= X-Google-Smtp-Source: AMsMyM6k0Z64A48kwS2YrIh5ozABVQWXIz9gKGJ41VuS260vYGjV8WzBpSP8gfKm8gJLFhIDiscBKw== X-Received: by 2002:a17:90b:3101:b0:203:776b:6494 with SMTP id gc1-20020a17090b310100b00203776b6494mr388079pjb.43.1663398389493; Sat, 17 Sep 2022 00:06:29 -0700 (PDT) Received: from localhost.localdomain (KD027092233113.ppp-bb.dion.ne.jp. [27.92.233.113]) by smtp.gmail.com with ESMTPSA id i11-20020a170902c94b00b00177faf558b5sm16241114pla.250.2022.09.17.00.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 00:06: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, corbet@lwn.net, david@redhat.com, osalvador@suse.de, shuah@kernel.org, Zhao Gongyi Cc: Akinobu Mita , Wei Yongjun Subject: [PATCH] lib/notifier-error-inject: fix error when writing errno to debugfs file Date: Sat, 17 Sep 2022 16:06:08 +0900 Message-Id: <20220917070608.28210-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=1663398390; 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=gB5h/T33V9gpZKvAPxPSR02YTU84Z6GoD+iIQZO//cY=; b=U9ZHFntWwaLKz4izpjCQngo3GeGmgNPQjED8gbg0obCvuVr47EG70eAlfjnnDetb6FX3vg RehcWy8TfbZIU4CM0extH+GOGiVxAdnBuhVZwzY6czAjahvFnvdsH5LZWCpZCKzAonZujs IByWmlk8Mdqi1zhPcAruMegDOVpkm/Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KH74j79o; spf=pass (imf21.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.214.170 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=1663398390; a=rsa-sha256; cv=none; b=RCBW16uSNm2XBZzR4L5o09nm+kuwdJKNk3Fb97U7qZrqNjW2JAQaDPsrSz56G0iskTtblt VB5rPaIyBi4rSKj62LQWXh2cpMIjrz8Mo3PwCx/CxQHFWMEbAFFoGwPpywkqr7RNUuygsC edLIiRFTBwzoNIiB2sVKXRdVGChb90E= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D62DB1C00BE X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KH74j79o; spf=pass (imf21.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: unxk5y3gdag8poh43irhpj3e5d43w74m X-HE-Tag: 1663398390-306619 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: Wei Yongjun Signed-off-by: Akinobu Mita --- 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)