RT-Thread / RT-Thread/rt-thread

一点儿想法,设备struct rt_device定义中的 void *user_data 是不是应该只留给用户使用

Open
#6,316 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

按照字面意思,void *user_data; 应该留给用户使用,目前在组件和软件包中都有占用;

有几次在写代码时,用到了这个指针,直到程序异常排查采发现组件占用了这个指针,被我修改了导致异常;
是不是应该对这个指针的使用明确一下。
或者组件和软件包避免使用这个指针;
或者使用者特别声明一下;
或者专门在device里给组件门专门留一个指针;
`
/**

  • Device structure
    */
    struct rt_device
    {
    struct rt_object parent; /**< inherit from rt_object */

    enum rt_device_class_type type; /< device type */
    rt_uint16_t flag; /
    < device flag */
    rt_uint16_t open_flag; /**< device open flag */

    rt_uint8_t ref_count; /< reference count */
    rt_uint8_t device_id; /
    < 0 - 255 */

    /* device call back */
    rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
    rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);

#ifdef RT_USING_DEVICE_OPS
const struct rt_device_ops ops;
#else
/
common device interface */
rt_err_t (*init) (rt_device_t dev);
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*close) (rt_device_t dev);
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void args);
#endif /
RT_USING_DEVICE_OPS */

#ifdef RT_USING_POSIX_DEVIO
const struct dfs_file_ops fops;
struct rt_wqueue wait_queue;
#endif /
RT_USING_POSIX_DEVIO */

void                     *user_data;                /**< device private data */

};
`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the struct rt_device declaration shown in the issue and inspect the component and package uses of user_data. Determine whether the pointer's ownership should be clarified, restricted, or replaced, then document the agreed policy and update affected uses. Done means the API contract is explicit and existing component and package behavior is consistent with it.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.