Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1683102pxm; Thu, 24 Feb 2022 07:33:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNORJGpsQePhvxGAuO6+SDoSgkzsgqGjP0x89TS9t+Sf/x/RFSnzAYBMM9kt8io/oIRH9d X-Received: by 2002:a17:90b:3b4d:b0:1bc:a5a7:b389 with SMTP id ot13-20020a17090b3b4d00b001bca5a7b389mr3345258pjb.148.1645716808058; Thu, 24 Feb 2022 07:33:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645716808; cv=none; d=google.com; s=arc-20160816; b=KEXm1BRtn3ncoqgKvjI9/azqyw/RO2KF392vq5p9jZ3r9Awah1gFnyziwhOn8y+nit c0QR4h34vWbmsq2hWoh3WjBBI3q2c+3zQXLUNs4V29eeRqLt8Z7eJ7rdKqfQu7uCdKvx pRUIknZ90mVLv+hb2VDE4k+hcV+IzoLhEDfQBrTwH2h9jYWwMsvzwmDoQovZJcpNcioL 9UdfeDl3DegFg0erlqELKYJcZEYP4WC8hzK+qLNIsnvRgBOt8Tncm/h6tVyWnbJ8Qp4u vkThhpHfP6Z5jbw9ABgbZHrsKSMvszGUIfK2A60PfnmVS4/Da4Abu4J4x9NABkWlBOMn a+tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Xkij7v3f9oBOVQeobW2OmDnzLUXFDJ0PaS8VJOLK7RE=; b=L9PPr6z4jMuNJdBPj8SFjrHgd2o21XLaJWrx6tWHfvvWeYC2F2GvsvRBLXfdoTkwWn ge6vZdRxbH5XZYTMO/KFFWPsIOL3wLwxnghRf/cgYf0gkosjh2tSoqdtKJIP+J+a40gT eb1COzNyBw/Bv24ws4CLDquL6Rtqlg5l+ey9B2AyzhTcrdCqc1gDjRe2DaeYNK2vitXZ g2k8ej+DAUxRaJCHGcXpNqut0lwbzPKa0ApwiFFvyVNDmYs5K2QyZfdmwTN2zEBNe8e4 BCBIa2mG+EG4L07XQ2CRMJr0DCSdXpbBL3BU/zzwbnQc73MNjwZ66ENFnCtJ22DW8PnK 1T6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13si484663pgo.297.2022.02.24.07.33.10; Thu, 24 Feb 2022 07:33:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234227AbiBXL57 (ORCPT + 99 others); Thu, 24 Feb 2022 06:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbiBXL5y (ORCPT ); Thu, 24 Feb 2022 06:57:54 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9591230E53; Thu, 24 Feb 2022 03:57:14 -0800 (PST) Received: from fraeml708-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K4BFg0hgRz6H6sb; Thu, 24 Feb 2022 19:56:23 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml708-chm.china.huawei.com (10.206.15.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 24 Feb 2022 12:57:12 +0100 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 24 Feb 2022 11:57:10 +0000 From: John Garry To: , CC: , , , Xiang Chen , Qi Liu , John Garry Subject: [PATCH 5/6] scsi: hisi_sas: Limit users changing debugfs BIST count value Date: Thu, 24 Feb 2022 19:51:28 +0800 Message-ID: <1645703489-87194-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1645703489-87194-1-git-send-email-john.garry@huawei.com> References: <1645703489-87194-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 From: Xiang Chen Add a file operation for "cnt" file under bist directory, so users could only read "cnt" or clear "cnt" to zero, but cannot randomly modify. Signed-off-by: Xiang Chen Signed-off-by: Qi Liu Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 52 +++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 43d57b68c208..ad3e2db0f520 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -3975,6 +3975,54 @@ static const struct file_operations debugfs_bist_phy_v3_hw_fops = { .owner = THIS_MODULE, }; +static ssize_t debugfs_bist_cnt_v3_hw_write(struct file *filp, + const char __user *buf, + size_t count, loff_t *ppos) +{ + struct seq_file *m = filp->private_data; + struct hisi_hba *hisi_hba = m->private; + unsigned int cnt; + int val; + + if (hisi_hba->debugfs_bist_enable) + return -EPERM; + + val = kstrtouint_from_user(buf, count, 0, &cnt); + if (val) + return val; + + if (cnt) + return -EINVAL; + + hisi_hba->debugfs_bist_cnt = 0; + return count; +} + +static int debugfs_bist_cnt_v3_hw_show(struct seq_file *s, void *p) +{ + struct hisi_hba *hisi_hba = s->private; + + seq_printf(s, "%u\n", hisi_hba->debugfs_bist_cnt); + + return 0; +} + +static int debugfs_bist_cnt_v3_hw_open(struct inode *inode, + struct file *filp) +{ + return single_open(filp, debugfs_bist_cnt_v3_hw_show, + inode->i_private); +} + +static const struct file_operations debugfs_bist_cnt_v3_hw_ops = { + .open = debugfs_bist_cnt_v3_hw_open, + .read = seq_read, + .write = debugfs_bist_cnt_v3_hw_write, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + static const struct { int value; char *name; @@ -4612,8 +4660,8 @@ static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba) debugfs_create_file("phy_id", 0600, hisi_hba->debugfs_bist_dentry, hisi_hba, &debugfs_bist_phy_v3_hw_fops); - debugfs_create_u32("cnt", 0600, hisi_hba->debugfs_bist_dentry, - &hisi_hba->debugfs_bist_cnt); + debugfs_create_file("cnt", 0600, hisi_hba->debugfs_bist_dentry, + hisi_hba, &debugfs_bist_cnt_v3_hw_ops); debugfs_create_file("loopback_mode", 0600, hisi_hba->debugfs_bist_dentry, -- 2.26.2