From patchwork Tue Mar 31 11:47:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Sarkar X-Patchwork-Id: 11467671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CDE021667 for ; Tue, 31 Mar 2020 11:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB988206DB for ; Tue, 31 Mar 2020 11:48:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ca+J3yvo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730542AbgCaLsN (ORCPT ); Tue, 31 Mar 2020 07:48:13 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:53723 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgCaLsM (ORCPT ); Tue, 31 Mar 2020 07:48:12 -0400 Received: by mail-pj1-f68.google.com with SMTP id l36so964720pjb.3; Tue, 31 Mar 2020 04:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6O0gMjSRqXI23LYvCLV0ocypchgJQJFmBiZQ3a3Giu4=; b=ca+J3yvo4W0T3ogR1fHJz8ZkjV8TeVcDN2yw0jVHdxZuficHrC3RPN1zyrjrh8mPhv vJ+2E5iTBwDCq/RAaUCeMswujQBQ6eePHlKPVUQvvIqA3zqbCyU88xypTbn1UmOZVDHP HL89ItRq6fJrm2RvQ5BFi2OHnrJvfU8tH0Me1GY0YPfufbqwD/KYxSfZIti0D5/+UALi WdO/ZDK87hOwvsST+NXh4NPqRj13hr+YzT78cdYge4IsvAZpMiF654qGNpEk4vbK3p8N FJpQ6pUTzlB4FNf283HQxtL+CRYWk7+OqQM284FbCUhn92rybGNm6QRQyLxz5k9E9rgT P1eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6O0gMjSRqXI23LYvCLV0ocypchgJQJFmBiZQ3a3Giu4=; b=UoBivIzKr8Un0HMwYK2okixTKiCZAJwD4upRkaFjEVvHSfHf+5e63D6ubYm6VJzgil Ek2ACybKPhb/qU1TCH6F7uIZblbhX+D115hs7fEs+UmFBJNaqFZ1geqJCYle5aNddXNt 1hLUbmIuHvqKpok/e7U70Sthd663Cp90Bwn5mEps1/jMzxYd8QRu0jVpg/tVrjIYxpb+ eOq9Vs+rsv/ysLXf3Tl42TWpPhTrc5e+EmNybMxf4VDjCRbQ3gBk3yRarz9OxFRvNZ2c MqOlL06b6j84NQgovlzCwv9gYFOLICfKTEysDPsGTp0XBWR1vPof4f2Tl2u7jDXCoofh eLaA== X-Gm-Message-State: AGi0PuYGO9jEZAHJkIa1NQ7hb9TC3IVEs+bHJqFbovnyeznDPIZz0l3S 7gtYjoiGm5m92suijLkTkECmYdTW8EieJg== X-Google-Smtp-Source: APiQypLaFIbNWxV2Rp8S+zw6UtzysQuM8vftpi6q/VbZSWzyrhdxbj4i3RaLdGhdgrnrTs7FRraLlQ== X-Received: by 2002:a17:90a:1911:: with SMTP id 17mr3448899pjg.65.1585655291196; Tue, 31 Mar 2020 04:48:11 -0700 (PDT) Received: from localhost.localdomain ([122.178.242.244]) by smtp.gmail.com with ESMTPSA id i15sm11601220pgc.74.2020.03.31.04.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 04:48:10 -0700 (PDT) From: Rohit Sarkar To: linux-iio@vger.kernel.org Cc: dragos.bogdan@analog.com, Rohit Sarkar , Lars-Peter Clausen , Michael Hennerich , Stefan Popa , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] iio: imu: adis16400: use DEFINE_DEBUGFS_ATTRIBUTE instead of DEFINE_SIMPLE_ATTRIBUTE Date: Tue, 31 Mar 2020 17:17:30 +0530 Message-Id: <20200331114732.14739-2-rohitsarkar5398@gmail.com> X-Mailer: git-send-email 2.23.0.385.gbc12974a89 In-Reply-To: <20200331114732.14739-1-rohitsarkar5398@gmail.com> References: <20200328063456.24012-1-rohitsarkar5398@gmail.com> <20200331114732.14739-1-rohitsarkar5398@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org debugfs_create_file_unsafe does not protect the fops handed to it against file removal. DEFINE_DEBUGFS_ATTRIBUTE makes the fops aware of the file lifetime and thus protects it against removal. Signed-off-by: Rohit Sarkar --- drivers/iio/imu/adis16400.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c index cfb1c19eb930..c8fcd40f58c0 100644 --- a/drivers/iio/imu/adis16400.c +++ b/drivers/iio/imu/adis16400.c @@ -258,7 +258,7 @@ static int adis16400_show_product_id(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops, +DEFINE_DEBUGFS_ATTRIBUTE(adis16400_product_id_fops, adis16400_show_product_id, NULL, "%lld\n"); static int adis16400_show_flash_count(void *arg, u64 *val) @@ -275,7 +275,7 @@ static int adis16400_show_flash_count(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops, +DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops, adis16400_show_flash_count, NULL, "%lld\n"); static int adis16400_debugfs_init(struct iio_dev *indio_dev) @@ -283,15 +283,16 @@ static int adis16400_debugfs_init(struct iio_dev *indio_dev) struct adis16400_state *st = iio_priv(indio_dev); if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) - debugfs_create_file("serial_number", 0400, - indio_dev->debugfs_dentry, st, - &adis16400_serial_number_fops); + debugfs_create_file_unsafe("serial_number", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_serial_number_fops); if (st->variant->flags & ADIS16400_HAS_PROD_ID) - debugfs_create_file("product_id", 0400, + debugfs_create_file_unsafe("product_id", 0400, + indio_dev->debugfs_dentry, st, + &adis16400_product_id_fops); + debugfs_create_file_unsafe("flash_count", 0400, indio_dev->debugfs_dentry, st, - &adis16400_product_id_fops); - debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, - st, &adis16400_flash_count_fops); + &adis16400_flash_count_fops); return 0; } From patchwork Tue Mar 31 11:47:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Sarkar X-Patchwork-Id: 11467673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9CBC1667 for ; Tue, 31 Mar 2020 11:48:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6D24208E0 for ; Tue, 31 Mar 2020 11:48:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dWHtUzeQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730693AbgCaLsT (ORCPT ); Tue, 31 Mar 2020 07:48:19 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38960 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgCaLsS (ORCPT ); Tue, 31 Mar 2020 07:48:18 -0400 Received: by mail-pl1-f195.google.com with SMTP id k18so3230014pll.6; Tue, 31 Mar 2020 04:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=69MDAmNWecKpofdaJ8R37Cfmm+mjxxlz6kLovvC8eNM=; b=dWHtUzeQCNnlshkvkAJulWssXaZvdkcJj3QIsmvb2ivhQYYOtF3mFxUDGirxGAG3lz 0BH69m+zRfU7bfVujzx8D23tApztMuqPR04mqXCTNgPuo6pwFMeimQURHig7LJOf1fUN evgeEkyeZyqMtQ4Ubn51zgP/jUmH6Q+hfpay50Xg9m+cj5BoRL1cUcNQDQKj/W84wbWE rgJvRrQZ/r8xU5J92YbJkWUqMy9HZQn3zyZJ96z8Mimi/NGQy16xF4D9Ieq2MHA8lEZq 5QafwbeJ4HTOEZikO4nEIKpdiLTCa6uK3kqowAdThkgX6aRYWLYIn90H0OKbTf+AKVUi DMpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=69MDAmNWecKpofdaJ8R37Cfmm+mjxxlz6kLovvC8eNM=; b=TOTdlzZnlu2mwTOJ+Pjj3qpYe5xtpf/6xHlQqxbXTKUsCWpZDDUZdjQTHNqCQPFZNO Vb4IFoZLNJUnWxjL7MKRIuIEdbBxBiQPVOCrwYb8FgMMmTqrg3QwsagCrmjbpgOCSonI C7xJRD/Z4xzCS8JgaYqsdznETHDaaiX2WlPwV+QlGkb2eyc860LvYZfPAxMTza7voENt 8tYYjJDqrSbmKNu75cyQqZy2EazW/AWOzukhSiHQz3Up5CDr2jQQLaELM98ltdWoCN0T RnXoqAbk4JyM6vvRboq6J/0WNThJDHamNY7CYZUxcEdFZ/SuflckVGye9kbv+5afi4U+ 82sg== X-Gm-Message-State: ANhLgQ0GtD7siwhnYiRamVXWECPXaVH3776qRNSt4wmSAgWguVeQf5KC OHec5871ATX05ZUE/OEexNDSjpH6lNyQwg== X-Google-Smtp-Source: ADFU+vuiR2Bk1INOg84gy/3iKqeZ2AoX8LJDpwX5kaP1UsgkNGnECWyUnfi3mOEZIgqDG//wEmQbxA== X-Received: by 2002:a17:902:7e05:: with SMTP id b5mr15613238plm.253.1585655296845; Tue, 31 Mar 2020 04:48:16 -0700 (PDT) Received: from localhost.localdomain ([122.178.242.244]) by smtp.gmail.com with ESMTPSA id i15sm11601220pgc.74.2020.03.31.04.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 04:48:16 -0700 (PDT) From: Rohit Sarkar To: linux-iio@vger.kernel.org Cc: dragos.bogdan@analog.com, Rohit Sarkar , Lars-Peter Clausen , Michael Hennerich , Stefan Popa , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] iio: imu: adis16460: use DEFINE_DEBUGFS_ATTRIBUTE instead of DEFINE_SIMPLE_ATTRIBUTE Date: Tue, 31 Mar 2020 17:17:31 +0530 Message-Id: <20200331114732.14739-3-rohitsarkar5398@gmail.com> X-Mailer: git-send-email 2.23.0.385.gbc12974a89 In-Reply-To: <20200331114732.14739-1-rohitsarkar5398@gmail.com> References: <20200328063456.24012-1-rohitsarkar5398@gmail.com> <20200331114732.14739-1-rohitsarkar5398@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org debugfs_create_file_unsafe does not protect the fops handed to it against file removal. DEFINE_DEBUGFS_ATTRIBUTE makes the fops aware of the file lifetime and thus protects it against removal. Signed-off-by: Rohit Sarkar --- drivers/iio/imu/adis16460.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/iio/imu/adis16460.c b/drivers/iio/imu/adis16460.c index 9539cfe4a259..f96cfd007957 100644 --- a/drivers/iio/imu/adis16460.c +++ b/drivers/iio/imu/adis16460.c @@ -87,8 +87,8 @@ static int adis16460_show_serial_number(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_serial_number_fops, - adis16460_show_serial_number, NULL, "0x%.4llx\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_serial_number_fops, + adis16460_show_serial_number, NULL, "0x%.4llx\n"); static int adis16460_show_product_id(void *arg, u64 *val) { @@ -105,8 +105,8 @@ static int adis16460_show_product_id(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_product_id_fops, - adis16460_show_product_id, NULL, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_product_id_fops, + adis16460_show_product_id, NULL, "%llu\n"); static int adis16460_show_flash_count(void *arg, u64 *val) { @@ -123,19 +123,22 @@ static int adis16460_show_flash_count(void *arg, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(adis16460_flash_count_fops, - adis16460_show_flash_count, NULL, "%lld\n"); +DEFINE_DEBUGFS_ATTRIBUTE(adis16460_flash_count_fops, + adis16460_show_flash_count, NULL, "%lld\n"); static int adis16460_debugfs_init(struct iio_dev *indio_dev) { struct adis16460 *adis16460 = iio_priv(indio_dev); - debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_serial_number_fops); - debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_product_id_fops); - debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, - adis16460, &adis16460_flash_count_fops); + debugfs_create_file_unsafe("serial_number", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_serial_number_fops); + debugfs_create_file_unsafe("product_id", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_product_id_fops); + debugfs_create_file_unsafe("flash_count", 0400, + indio_dev->debugfs_dentry, adis16460, + &adis16460_flash_count_fops); return 0; }