From patchwork Tue May 16 16:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 94796 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp543567vqo; Tue, 16 May 2023 09:11:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7A2lVxZ2XPNzP+SpRDnu2JF+plPWxEaZ3YFdONUW8FCXzMRdnoGUZ1h4UPf2um8MzagPO9 X-Received: by 2002:a05:6a20:3947:b0:104:b21f:26b0 with SMTP id r7-20020a056a20394700b00104b21f26b0mr18997836pzg.47.1684253505212; Tue, 16 May 2023 09:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684253505; cv=none; d=google.com; s=arc-20160816; b=g6dEDpTsAcYsXkv8V+6XgsABwPrnLmMj5SSQ83mbHWd3PdyODYTfX94hjHZSObW0D6 BDylkZMoK5ZYL2rZaJ6+UQWtfSriJ6YKtkSLQjqsZjJUUCVp0X1vuUPbmAkMUHOjqYhu /OWLb/rTm/ToIw96X6qGEfGedNFiB4rTXN7diyykeaDTMnKmqLxYq5XpfJjqAhDCNlSr /JWsYprxVxR/8fiUOYkVcA3krDXRJW7geq/VLh8D8MkA8YjdyPAWDKKCJGIDBWIcn96C E9zedLVxrTYNm04z+hbt75Vsrt6X1aXvHzvdMlIR9ACxxsu+YO/xP1RSMVwJOhad4fHU ZVNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T2DH6/H5m8Qazyq8fWgGGTIxlN/LEAb7+hM6ytoAYMY=; b=d78rzrVA3y6O3k9ZW10OToLBTMaeDJULXRSeUoKTNh3TEP9BB4LEmhgmp9BlpEUB66 7Ya4xIt/9JaqqPCj+y78NWI28BFnBiAo7ACe1I6oDFynIO7whXP9lD4ffHSRHdY2o2g1 S9BhzNi+211Yob8PTA/noj0Hncb0HLxTD9xa7ywnlS31V7SQU/38jcxU+C92xJxPuUGM eVPj4DfWArUIXIPVrZ941/vQlmqQ7pPzzeQpjaucuhPAMFCqpLwNlz5ZiFZIAicTxFxG qCV9hTCvtX2zmzczsMVD7eEG3K7UGXlMKxO/0bDLd8nYGTc3xDzPwvlrFyu/4/ZVhIjU ZW0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=jaYJo2OZ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j65-20020a638b44000000b0051b10b20ceasi20090098pge.893.2023.05.16.09.11.29; Tue, 16 May 2023 09:11:45 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=jaYJo2OZ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234527AbjEPQJg (ORCPT + 99 others); Tue, 16 May 2023 12:09:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbjEPQJJ (ORCPT ); Tue, 16 May 2023 12:09:09 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 920BA9EEF for ; Tue, 16 May 2023 09:08:34 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34GFMLXM013969; Tue, 16 May 2023 11:07:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=T2DH6/H5m8Qazyq8fWgGGTIxlN/LEAb7+hM6ytoAYMY=; b=jaYJo2OZNJaOaQrzjITNXQW+77MenPnRLDgfl4yJSF1ZEy4lESaGCIij26mkBdeoOcL3 jw8dqXTMd/lPIbf+go/3Tw4kfuwPUpiEi3CUuWdr7qE48C6GbsPVj7I/LpzW/H/mQfiV JRLbofGTer24W/7Kmh6ZfEaJn/3fQQsREwv5Yj+/1qGlLebFTH6Va+4FT/GEwLNWJb6J EuwwV65XH+BYiYBsGU2ANWfdS0WlbmdCp28sszGEpVvdbDfMOdYs5coM+wBmh8uJ3vN/ NT5cldcZCzXw+akmOEt3X8xBudYqH8jlySboURtFo9S2zwdxv8rfVBfqEcuAffOypIAd OQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3qj7y14epn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 May 2023 11:07:58 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 16 May 2023 11:07:56 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 16 May 2023 11:07:56 -0500 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.64.66]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 15B7211A8; Tue, 16 May 2023 16:07:56 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , Richard Fitzgerald Subject: [PATCH 1/5] debugfs: Prevent NULL dereference reading from string property Date: Tue, 16 May 2023 17:07:49 +0100 Message-ID: <20230516160753.32317-2-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230516160753.32317-1-rf@opensource.cirrus.com> References: <20230516160753.32317-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: F3BY0PdYc71JIRmuN6TytsC3HzMbVf3f X-Proofpoint-ORIG-GUID: F3BY0PdYc71JIRmuN6TytsC3HzMbVf3f X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766067803400470287?= X-GMAIL-MSGID: =?utf-8?q?1766067803400470287?= Check in debugfs_read_file_str() if the string pointer is NULL. It is perfectly reasonable that a driver may wish to export a string to debugfs that can have the value NULL to indicate empty/unused/ignore. Signed-off-by: Richard Fitzgerald --- fs/debugfs/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f971c880dde..2c085ab4e800 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -878,6 +878,9 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf, return ret; str = *(char **)file->private_data; + if (!str) + return simple_read_from_buffer(user_buf, count, ppos, "\n", 1); + len = strlen(str) + 1; copy = kmalloc(len, GFP_KERNEL); if (!copy) { From patchwork Tue May 16 16:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 94805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp550029vqo; Tue, 16 May 2023 09:21:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GbwWsOaWZUastV2Qf009++m1+tlXeaHutO1yfKwXW/fUyJc86aN+WKwKQ8d0RaDlhNRLm X-Received: by 2002:a05:6a20:1448:b0:105:55a7:d5ff with SMTP id a8-20020a056a20144800b0010555a7d5ffmr13546717pzi.28.1684254064569; Tue, 16 May 2023 09:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684254064; cv=none; d=google.com; s=arc-20160816; b=AmtJ2m2W36puFPed5Ll4IWT0b6xhMCmNrhj21hk43m2q7AW3EY/rrb+xKzjVmBJYBx RE0h4tn3xWnBnBq0Lx4ibTWxnnMlfXtjK/wlNRZzO4XB7GQBXOFWSMLqd/e/RexLX9lB fRt6XF0kUPnSMFpjZjPsYDIjJSKpZZ+BYOBsKul8BULVDcO3dLZPFJW/FT9AMeC/epBY PwvdtbilVa/d5aBH9uvtCS6xP4k9zCmhdiKVu/rwVYlVEyWdEiFTIJakh0lFsVu+KvOU L/PXp24sPF+pozFjfLdhk3Kt9KQi0P56Hg5NSEzoNROMSYQQACtNYDG/2E5WyXhHddm8 Nycw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0NeDmDYR5mVb0sXj7lokIcwNiD3MIiyy9ewxIBZOeUo=; b=c36e0HDnPECMn48BboZVzX4Q3FqxzdGopLjz2fkHbkGnk3QPV0fvH4HBfuk7MDgKWQ nvPqYjpWx8bHmIAY3+kvjx7kYDUE4FkcDM0Q86JbnCNL5k6LmpwxHIJ0RcjY6z6BvG9o KfmJqmPFz5CQeVEA4VlYXWDuXsSVSuCL5dn8pVkW3y0rQu2qEmetwF9L3hE+TttLmMFH l0BbhpwnG6QH1vB5bewHHlDtmA9qhRQCtIuc4RT9tumAlio4UFSFi5YrI41c8k3F0KRR R74UujD/QPDNIipt0NCXdvTYeFKzz0VGQWu9RVm1hq2IKCBTIFxN4ohcQqI8jR0FEi0T IV1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=CJG1X+oA; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x185-20020a6386c2000000b00528c6c2ea96si5706539pgd.306.2023.05.16.09.20.51; Tue, 16 May 2023 09:21:04 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=CJG1X+oA; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234419AbjEPQJy (ORCPT + 99 others); Tue, 16 May 2023 12:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbjEPQJR (ORCPT ); Tue, 16 May 2023 12:09:17 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83FCD041 for ; Tue, 16 May 2023 09:08:42 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34GFMCae029111; Tue, 16 May 2023 11:07:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=0NeDmDYR5mVb0sXj7lokIcwNiD3MIiyy9ewxIBZOeUo=; b=CJG1X+oA5jqftgZprA6nxVBqXiq705NNaF8esSbWzKVvFCWmmCRSi2yJ6jXAXuaSuG7Q CQ6yxGY8E2rhhrZp9fcultqAtUpZAF3Y/lPPfI3Nanf/LCO+RoUgqoMcIRy0amcLxejU lko6q+1DorRCyCSlPnZj3cqV7OQK/3NkuriX/XyzRHOzT+wKlqS6ptaPgFYHVddqZXRD /jVsoy/JfwNRfjUXklyM0y+6e5jpE5QDxeT4aHG1aZ+1IqOFmCEctk+K03C3DnATvLsC /pLc8cPN2FzTAPQQtUs9mLTnpgPpI52+J0Txrx2lKHITUHJhr56nhEcWFYyG4n2/xLKM IQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qj6ymvnvm-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 May 2023 11:07:58 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 16 May 2023 11:07:56 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 16 May 2023 11:07:56 -0500 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.64.66]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 62E7FB38; Tue, 16 May 2023 16:07:56 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , Richard Fitzgerald Subject: [PATCH 2/5] debugfs: Remove kerneldoc that says debugfs_create_str() returns a value Date: Tue, 16 May 2023 17:07:50 +0100 Message-ID: <20230516160753.32317-3-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230516160753.32317-1-rf@opensource.cirrus.com> References: <20230516160753.32317-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: krTL3GHzXkYZlwi_we7-r2_1SiwQ9IqS X-Proofpoint-ORIG-GUID: krTL3GHzXkYZlwi_we7-r2_1SiwQ9IqS X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766068389890166259?= X-GMAIL-MSGID: =?utf-8?q?1766068389890166259?= Remove the lines of kerneldoc that say debugfs_create_str() returns a struct dentry *. The function does not return a value. Signed-off-by: Richard Fitzgerald --- fs/debugfs/file.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 2c085ab4e800..0c039a3d9a42 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -943,15 +943,6 @@ static const struct file_operations fops_str_wo = { * This function creates a file in debugfs with the given name that * contains the value of the variable @value. If the @mode variable is so * set, it can be read from, and written to. - * - * This function will return a pointer to a dentry if it succeeds. This - * pointer must be passed to the debugfs_remove() function when the file is - * to be removed (no automatic cleanup happens if your module is unloaded, - * you are responsible here.) If an error occurs, ERR_PTR(-ERROR) will be - * returned. - * - * If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will - * be returned. */ void debugfs_create_str(const char *name, umode_t mode, struct dentry *parent, char **value) From patchwork Tue May 16 16:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 94795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp543359vqo; Tue, 16 May 2023 09:11:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65EqD8NE3fYxVOZTHJLX/5y2uyGbvxu71Mzu7KnaXoq5y05EysuI35sx/AG/xY16i8rw0D X-Received: by 2002:a05:6870:898f:b0:192:70ca:da4 with SMTP id f15-20020a056870898f00b0019270ca0da4mr23270849oaq.10.1684253488861; Tue, 16 May 2023 09:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684253488; cv=none; d=google.com; s=arc-20160816; b=sG8Rq6fd9s3+vUaZOpp0WTVWULR+Xm2QZ6jK+e+YsK6cKNj1i1jvKzmxY6Kv5oPI81 AE8cRS2vOEDgvSgNpXb1FxoLuB/e9SUtx1bT6Ef9IULzTv0lgWCEpAXAw/IRJt3t5Rsm yvqhwtymCrJE8vb+Kj18bVfw1pliE4NRwaq2OigocM0b6NQO7IEzB/E9rB9O6IYubcr+ 23kCFgSyD+Mi87hOGb/YDbEd8Ix1FX3efoTt24fnBhOmNjEijfWLkwIILmWGhcrqtkaf BNDJWbEaJoC5sH4xMFoT/o1bohu6jgN4zS1bcPqVQ+PNl0DG2HqpDkWCWIayvLdoWwLK LRYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+MDWXt5D6nc/s9cRAPjbV0EysPuWW1pUM4Nf/uIC2MA=; b=GNJtNCFngvGAecEXd+CQcn4RpRMkq/QuFWMcoCv5FG/QexcdjvFqBZayoPzeItDr3V DUrxJuTPqlS1tBrx8sTuh1gm3Ge7O9QD+jPTbed0QydzGpO6TiBpE4/Kr2POr6ziqDrW iLhPwvAoOVU0q1Y3qgyez+lONEZT2VRYCSwox/412lQH3XvwsXLxIfdAydCYJ99HhZN9 gEaEJQBgcc2ftqihxklgue2zz9V6qxdGVeGJ39R/qOtLfhuNrWpYkRpLn4UXQyj+jt8j xTxlW89FrXMwC+12LlnPQfHzpfY/WpC+lU5YsuuFED0KPt3cTKv6JINXVJrFn+qrKoXj 4YFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Rmr3LlMw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020a056870819400b00199aad87a98si4828470oae.215.2023.05.16.09.11.14; Tue, 16 May 2023 09:11:28 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Rmr3LlMw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234513AbjEPQJa (ORCPT + 99 others); Tue, 16 May 2023 12:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234113AbjEPQIu (ORCPT ); Tue, 16 May 2023 12:08:50 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB8BA27F for ; Tue, 16 May 2023 09:08:31 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34GFMCaf029111; Tue, 16 May 2023 11:08:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=+MDWXt5D6nc/s9cRAPjbV0EysPuWW1pUM4Nf/uIC2MA=; b=Rmr3LlMw/YzMnqh5fHSrsIYUIu3t91HB1bUpUMYOn/G+MCLGiFjiny3G9qkMthTeFwrh tMdvfd4OPFjixYQ+Oh/vTWM1C62ungDPRVe6eWBHQUAavqi0FpEJ+LqClY7mzy4xNiD9 p3ONybZbxk8bErJhFUYzCTwMWJ9jvjJCSP9y2ORT/Kyk3yY/z/Th4gGV9O5QryF+Z3zS qVIjk1T82+YIYwdWaKNQxUvc1nthJQKVsWQwhzQjCi65sm9bv4+GZLc37NQNuBF4gL5N wqtPlt2ofc3BAV93ApkKpu3GZI9EX1+tctQwL76CKKIfjV2mZUHMfyVqxGAey+9ThpBu 0w== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qj6ymvnvm-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 May 2023 11:07:59 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 16 May 2023 11:07:56 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 16 May 2023 11:07:56 -0500 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.64.66]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id AC99111A8; Tue, 16 May 2023 16:07:56 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , Richard Fitzgerald Subject: [PATCH 3/5] debugfs: Update debugfs_create_str() kerneldoc to warn about pointer race Date: Tue, 16 May 2023 17:07:51 +0100 Message-ID: <20230516160753.32317-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230516160753.32317-1-rf@opensource.cirrus.com> References: <20230516160753.32317-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: Of7ZDDsEtC4tmVWJr_igdUJqwZdbJ2F7 X-Proofpoint-ORIG-GUID: Of7ZDDsEtC4tmVWJr_igdUJqwZdbJ2F7 X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766067786560976410?= X-GMAIL-MSGID: =?utf-8?q?1766067786560976410?= Add a warning to the debugfs_create_str() kerneldoc that the char * pointer value must not change after the function returns, because of a race with debugfs_read_file_str() accessing the pointer. The only safe case is a change from NULL to non-NULL because in that case debugfs_read_file_str() will see either the NULL or the valid pointer. Signed-off-by: Richard Fitzgerald --- fs/debugfs/file.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 0c039a3d9a42..77794871f26d 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -938,11 +938,18 @@ static const struct file_operations fops_str_wo = { * directory dentry if set. If this parameter is %NULL, then the * file will be created in the root of the debugfs filesystem. * @value: a pointer to the variable that the file should read to and write - * from. + * from. The char* pointer must not change, except from NULL to + * non-NULL. * * This function creates a file in debugfs with the given name that * contains the value of the variable @value. If the @mode variable is so * set, it can be read from, and written to. + * + * The char* pointed to by @value must not change after calling this + * function EXCEPT that it may change from NULL to non-NULL. This is to + * prevent the file read from accessing a stale pointer. A change from + * NULL to non-NULL is the only safe change, because the read will + * instantaneously see either NULL or the valid pointer. */ void debugfs_create_str(const char *name, umode_t mode, struct dentry *parent, char **value) From patchwork Tue May 16 16:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 94797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp544721vqo; Tue, 16 May 2023 09:13:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4efXu1ZY2vUnF6EdtLBDzIVgXbSzIU5YSvJcjv2OyRH8HxRDJzoRfr/MV2TLxbpsapPYg1 X-Received: by 2002:a4a:91cf:0:b0:537:f9d4:a44c with SMTP id e15-20020a4a91cf000000b00537f9d4a44cmr10285389ooh.5.1684253608502; Tue, 16 May 2023 09:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684253608; cv=none; d=google.com; s=arc-20160816; b=NdMR/fQ/CC4sLxqeb6dmhox7R/F1/w+j1hqnlp17pedqcNJj+EmjrSY2qC85uJBYRh K2FdjNlbnrWGqSYhafJpdWocmNIkITV07isQ4xm5XW3XhGPNqAnd1DmT906tRP1b7bXN YBd2piIR75bil6fwzqO4/eH4bhUDGX8ghrUyNRUSuqzQ6upfLpBKDIu4Ki9aU7vTgcOi Otw8f/mGWsWngN8nwmt1FkxGUcG/aKpkbhhOLe5wj6OQgEo8xm4K/uHK6/IcfBkCqfYZ 9gDnnPHxmrzudErBd0AN++LFigdeoJVRYvVTmHQaMpZGootqKF+ldSKManY5YbX3aBno ij5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F8xUGENuEwEs7uQzjquZ4RM9syPSnoMdIovl2nu8iKw=; b=LEbmDx/fepXAvfGhGYSLcJjLukeVvkkFiaYGL1zo+e5M+XMpEQhbfrrJ4yXg/M5Z/h k4TP9zA4FJHLc8iFGnAKG+ngIYvagb21bThb3RiTQFSb4raPxKmQ5o+iNl5ef/NWXlN6 o6GWhxVLd4KXaiB+o404M0mZoL2UF1UMZL0cbAIwCyydH2hWpdH4NicU7FNK9MB4buex 2HfV3R36wpwX4q/4QhoiScpuuwj63yl741u+4iSoy0zIRSrWvyVssVw1t86r5QgLHCLh pdxC+nV5Q71ELxoexrLOgybWwCnHErqsEMyQ202e3BNHAdOM7tweBEeQwyI3fLvfFZlc OTTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=o2MZWLqy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a544615000000b0038c5b41e9e9si11910384oip.252.2023.05.16.09.13.13; Tue, 16 May 2023 09:13:28 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=o2MZWLqy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230434AbjEPQMT (ORCPT + 99 others); Tue, 16 May 2023 12:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjEPQMJ (ORCPT ); Tue, 16 May 2023 12:12:09 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2574C7EDA for ; Tue, 16 May 2023 09:11:56 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34GFMCag029111; Tue, 16 May 2023 11:08:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=F8xUGENuEwEs7uQzjquZ4RM9syPSnoMdIovl2nu8iKw=; b=o2MZWLqy3qc74JOMWbKy7yOMuDXIAs11ei9hLRcKY8cgm/a8/ANlQN4Y+x9PUXujnlu1 juAPiR9SmSDWvtSZVPOLT9FIft3Icxy+9Kpm4fJ7lwfak68xG7/8xgTderubFN2qyhsn zHEiADNjfCvSSz351qHQ43iWUmv7Zahi/Bfa1L7qsgP5r0z2q0B1o9cPJUNAFI76cAIY Rc8QrwbQruxKhaxyesAnfitFEHuV66DqvWGGdfxcj1nTJAd5n4/c31B3gGgXb2gD3knV gVfjAgLb9TW7wC7irCj8SZBHYU+WYtz2WHIksle1SijAbM8H8evlx9TtQVU2UAMX5IIx lg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qj6ymvnvm-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 May 2023 11:08:00 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 16 May 2023 11:07:57 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 16 May 2023 11:07:57 -0500 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.64.66]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 0231615A2; Tue, 16 May 2023 16:07:56 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , Richard Fitzgerald Subject: [PATCH 4/5] debugfs: Move debugfs_create_str() export to correct location Date: Tue, 16 May 2023 17:07:52 +0100 Message-ID: <20230516160753.32317-5-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230516160753.32317-1-rf@opensource.cirrus.com> References: <20230516160753.32317-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: x9izteXP3epPZGvRq7go-RI4rY2GAPCt X-Proofpoint-ORIG-GUID: x9izteXP3epPZGvRq7go-RI4rY2GAPCt X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766067912096938240?= X-GMAIL-MSGID: =?utf-8?q?1766067912096938240?= Move the EXPORT_SYMBOL_GPL for debugfs_create_str() to where it should be, immediately after the function it refers to. Signed-off-by: Richard Fitzgerald --- fs/debugfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 77794871f26d..d3892d01a8b4 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -902,7 +902,6 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf, return ret; } -EXPORT_SYMBOL_GPL(debugfs_create_str); static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) @@ -957,6 +956,7 @@ void debugfs_create_str(const char *name, umode_t mode, debugfs_create_mode_unsafe(name, mode, parent, value, &fops_str, &fops_str_ro, &fops_str_wo); } +EXPORT_SYMBOL_GPL(debugfs_create_str); static ssize_t read_file_blob(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) From patchwork Tue May 16 16:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 94794 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp543353vqo; Tue, 16 May 2023 09:11:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Y27rBA89CNha5E6r2jKFxp4uhWajUlzFetC6n0KO/7Pf5M+NJOQuMTz03cXR5wjON2tzD X-Received: by 2002:a05:6808:1888:b0:396:e69:c624 with SMTP id bi8-20020a056808188800b003960e69c624mr3994812oib.33.1684253488129; Tue, 16 May 2023 09:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684253488; cv=none; d=google.com; s=arc-20160816; b=Uy8XK0Gw0VJnEGhC0130pCClVmOdumZzUoMINXIsshLx6YxtDYoaJLvYmRPNeVj5jt EZj+22gS2ZH9KNZtHs6SZLjWXtSlmjZc7JkQ5fA8au4RN50iXl7GIDLBNzFpXsliVDwV K1Y4r1glN625983f7qDmQzYkiXEFag5hd7tcmiFdbW1KDB4IYLFYKK5bDt69kUr0qp1U VFVJxrKezYKTavHH2NaTFUr9G7l4PHWfTus2B3WLJb2LxP4VQQ6fcvihfQMuBAmpdohO pao8DObIcLbTBQsQS27tpbo/Vw7CBSPzUKeP026yTxQ57Vxsc1CZZEyQ7DQf1XvsNmpi jyOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NFIjHQw+dqpTNYvDnYxYQW3RAgGogay2/AQ3zCJQwvE=; b=AEyRs41r01iegMQwDubg9E+Ov+KH51T1S/I2Pion1f+dLq7yZ+568qw56erxRDtBHQ m+mtMs85ia8LUqghekLERUt9IIb53usqdMlyu4lbTQrjxhKj3oXXVIkL/xQVQM11NZjV X3JhSIguDw/LxgHNO5WmIuOS7GnuFB1dVGDlkKxs3yBN44SKLdoXrcyHirwzUSGtn6LB HT697d3NzqRQbbfAybMgSJhNsk8L6Lw6ROKq5YJMG2nLzaRl65kgz8tYSZKLAkGHdEfa yT6rotpSxXGS9teFjZANcRllDRr27ILjvOXPiM4hVi6su+2P2qvCkViuLiDmj9jMkCGW KTqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ldwvqhDo; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fm7-20020a056808650700b003961d393f5dsi2329313oib.277.2023.05.16.09.11.14; Tue, 16 May 2023 09:11:28 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ldwvqhDo; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbjEPQJc (ORCPT + 99 others); Tue, 16 May 2023 12:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233643AbjEPQI6 (ORCPT ); Tue, 16 May 2023 12:08:58 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3303493FC for ; Tue, 16 May 2023 09:08:32 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34GFMCah029111; Tue, 16 May 2023 11:08:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=NFIjHQw+dqpTNYvDnYxYQW3RAgGogay2/AQ3zCJQwvE=; b=ldwvqhDoaNVW8CPDVufWunIGvcwqF/CleVU+kYz0BKU1WRds8BiJyGJD46ryuoHqidxK L0eDUrRqVhYtccuhW2M7blL4ezPA610EEFbrqanxcR/+HnqDc/jTF563nGzwxwzdsnKf cnn/6tyeBnXr433shXDC54hs3bqVGyE11Uj52v9/ToL14fYwLXuzMIkw916QsyK5XwQF VglVDybjJJ0E33CeKriTyz7JGKSALpkR0r1zuCCy3TKdgRPRzKr7sg/O0r7waus/s4HC bQhMhfFgaIzJh+Yk9hLpJv9CwyUMjKwxEH9PKYIkrWxy3DSmVhPOrnpHPUgexhyf54hP eA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qj6ymvnvm-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 May 2023 11:08:00 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 16 May 2023 11:07:57 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 16 May 2023 11:07:57 -0500 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.64.66]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 50D16B38; Tue, 16 May 2023 16:07:57 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , Richard Fitzgerald Subject: [PATCH 5/5] debugfs: Add debugfs_create_const_str() Date: Tue, 16 May 2023 17:07:53 +0100 Message-ID: <20230516160753.32317-6-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230516160753.32317-1-rf@opensource.cirrus.com> References: <20230516160753.32317-1-rf@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: rzWXC6kM24RH8ev80R6c-1h1eGlYdk9q X-Proofpoint-ORIG-GUID: rzWXC6kM24RH8ev80R6c-1h1eGlYdk9q X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766067785537483183?= X-GMAIL-MSGID: =?utf-8?q?1766067785537483183?= Add a wrapper for debugfs_create_str() that takes a const char **. It's never nice to have to cast a const pointer to a non-const to be able to pass it to an API. It always looks suspicious and it is relying on "knowing" that it's safe. A function that explicitly takes a const pointer is creating a contract that a const pointer is safe. Signed-off-by: Richard Fitzgerald --- include/linux/debugfs.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index ea2d919fd9c7..2723690aedd1 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -401,4 +401,31 @@ static inline void debugfs_create_xul(const char *name, umode_t mode, debugfs_create_x64(name, mode, parent, (u64 *)value); } +/** + * debugfs_create_const_str - create a debugfs file that is used to read a string value + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @value: a pointer to the variable that the file should read from. + * The const char* pointer must not change, except from NULL to + * non-NULL. + * + * This function creates a file in debugfs with the given name that + * contains the value of the variable @value. + * + * The const char* pointed to by @value must not change after calling this + * function EXCEPT that it may change from NULL to non-NULL. This is to + * prevent the file read from accessing a stale pointer. A change from + * NULL to non-NULL is the only safe change, because the read will + * instantaneously see either NULL or the valid pointer. + */ +static inline void debugfs_create_const_str(const char *name, umode_t mode, + struct dentry *parent, + const char **value) +{ + debugfs_create_str(name, mode & ~0222, parent, (char **)value); +} + #endif