Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9314179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:04:28+00:00 2026-06-19T02:04:28+00:00

I have created a simple test device. My intention is to create a few

  • 0

I have created a simple test device. My intention is to create a few custom sysfs files and get setting from them. I tried first by adding a kobject and with my own sys_ops. That worked well. However, trying to do the same by using the platform device is giving me a file which I cannot read or write to. Can any one tell me whats wrong here?

=============sysfs_file.c==================================

    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/platform_device.h>
    #include <linux/kobject.h>
    #include <linux/slab.h>

    struct kobject *myob;
    char *ops_buffer;
    struct attribute my_atr = {
    .name = "custom_attrbute",
    .mode = S_IWUGO|S_IRUGO,
    };
    int atp_probe(struct platform_device *dev)
    {
        printk("%s\n", __func__);
        myob = &dev->dev.kobj;
        ops_buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
        sysfs_create_file(myob, &my_atr);
        return 0;
    }
    int atp_remove(struct platform_device *dev)
    {
    printk("%s\n", __func__);
        sysfs_remove_file(myob, &my_atr);
        kfree(ops_buffer);
        return 0;
    }
    struct platform_device atp_dev = {
        .name = "Aerrow_Test_Platform",
        .id = 0,
    };
    struct platform_driver atp_drv = {
        .driver = {
        .name = "Aerrow_Test_Platform",
        .owner = THIS_MODULE,
        },
        .probe = atp_probe,
        .remove = atp_remove,
    };
    static int __init sfst_init(void)
    {
        int ret;
        printk("%s\n",__func__);
        ret = platform_device_register(&atp_dev);
        printk("%s: device add ret = %d\n", __func__, ret);
        ret = platform_driver_register(&atp_drv);
        printk("%s: driver register ret = %d\n", __func__, ret);
        return 0;
    }
    static void __exit sfst_exit(void)
    {   
        printk("%s", __func__);
        platform_driver_unregister(&atp_drv);
        platform_device_del(&atp_dev);
    }
    module_init(sfst_init);
    module_exit(sfst_exit);
    MODULE_LICENSE("GPL");

====================================================================================
The output is:

preetam@preetam-Veriton-Series:ko_training$ cd /sys/devices/platform/Aerrow_Test_Platform.0/
preetam@preetam-Veriton-Series:Aerrow_Test_Platform.0$ ls
custom_attrbute  driver  modalias  power  subsystem  uevent
preetam@preetam-Veriton-Series:Aerrow_Test_Platform.0$ cat custom_attrbute 
cat: custom_attrbute: Input/output error
preetam@preetam-Veriton-Series:Aerrow_Test_Platform.0$ echo "HELLO" > custom_attrbute 
bash: echo: write error: Input/output error
preetam@preetam-Veriton-Series:Aerrow_Test_Platform.0$ cat custom_attrbute cat: custom_attrbute: Input/output error

Is the platform device’s ktype ops methods unable handle additional attributes or is something wrong with my code? The same thing works if I create my own kobject and put this attribute under that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:04:29+00:00Added an answer on June 19, 2026 at 2:04 am

    “A bare attribute contains no means to read or write the value of the attribute. Subsystems are encouraged to define their own attribute structure and wrapper functions for adding and removing attributes for a specific object type.” – from kernel.org/doc/Documentation/filesystems/sysfs.txt.

    You can try device_attribute instead of this bare attribute structure. Also define your own show and store to read and write your sysfs entry.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple test form with FormBorderStyle = FixedToolWindow by default and
I am using SQL Server 2008 Enterprise. I have created a very simple test
I have a simple controller test, containing a.o. the following code: context POST :create
I'm trying to create a very simple REST server. I just have a test
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple
I have created a simple test solution using Entity Framework and WCF. I have
I have created a simple test harness in python for my ASP .net web
I am using Ruby on Rails 3.2 and have created a simple test blog
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.