Skip to content

Conversation

kurisaW
Copy link
Member

@kurisaW kurisaW commented Sep 22, 2025

拉取/合并请求描述:(PR description)

[

1.完善sal初始化参数检查
2.修改SOCKET_TABLE_STEP_LEN为用户可配置参数

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves error handling and validation in the SAL (Socket Abstraction Layer) component by enhancing parameter checking and making configuration more flexible.

  • Enhanced socket initialization with comprehensive parameter validation including protocol range checks and domain/type/protocol combination validation
  • Made SOCKET_TABLE_STEP_LEN configurable through Kconfig instead of hardcoded define
  • Improved error return values to provide more specific error information instead of generic -1

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
components/net/sal/src/sal_socket.c Enhanced socket_init() with parameter validation, improved error logging, and better error return handling
components/net/sal/include/sal_socket.h Added new includes and macros for protocol validation and domain/type/protocol combination checking
components/net/sal/Kconfig Added configurable SOCKET_TABLE_STEP_LEN parameter
Comments suppressed due to low confidence (1)

components/net/sal/src/sal_socket.c:1

  • English: The constants PROTOCOL_TLS and PROTOCOL_DTLS are referenced but may not be defined. This could cause compilation errors if TLS support is not enabled or these constants are not available in the included headers.

中文:引用了 PROTOCOL_TLS 和 PROTOCOL_DTLS 常量,但这些常量可能未定义。如果未启用 TLS 支持或这些常量在包含的头文件中不可用,这可能导致编译错误。

/*

Comment on lines +17 to +20
#include "sal_low_lvl.h"
#include "sal_msg.h"
#include "sal_netdb.h"
#include "sal_tls.h"
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: These includes appear to be added unnecessarily. The header file should only include what it directly uses. If these headers are needed for the VALID_COMBO macro, consider moving the macro to the source file or including only the specific headers that define the required constants.

中文:这些包含文件似乎是不必要添加的。头文件应该只包含它直接使用的内容。如果这些头文件是 VALID_COMBO 宏所需要的,考虑将宏移动到源文件中,或者只包含定义所需常量的特定头文件。

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rbb666 这个是不是可以考虑放到sal_socket.h中,后面用户直接调用这个sal_socket.h就可以了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不推荐加到这里,交给用户加吧,其他的文件也是这么干的:

Comment on lines 131 to 133
((domain) == AF_NETLINK && (type) == SOCK_RAW && (protocol) == 0) || \
/* Add more combos for AF_CAN, AF_AT, AF_WIZ if needed */ \
1 /* Default allow for unknown, but log warning */ \
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: The VALID_COMBO macro always returns true due to the final '1' condition, making the validation ineffective. This defeats the purpose of parameter validation. Consider removing this fallback or implementing proper validation for all supported domain/type/protocol combinations.

中文:由于最后的 '1' 条件,VALID_COMBO 宏总是返回 true,使验证失效。这违背了参数验证的目的。考虑移除这个回退条件,或者为所有支持的域/类型/协议组合实现适当的验证。

Suggested change
((domain) == AF_NETLINK && (type) == SOCK_RAW && (protocol) == 0) || \
/* Add more combos for AF_CAN, AF_AT, AF_WIZ if needed */ \
1 /* Default allow for unknown, but log warning */ \
((domain) == AF_NETLINK && (type) == SOCK_RAW && (protocol) == 0) \
/* Add more combos for AF_CAN, AF_AT, AF_WIZ if needed */ \

Copilot uses AI. Check for mistakes.

The ability that check internet status is provided by RT-Thread.

config SOCKET_TABLE_STEP_LEN
int "Configurate socket table step length"
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English: 'Configurate' should be 'Configure' in the description text.

中文:描述文本中的 'Configurate' 应该是 'Configure'。

Suggested change
int "Configurate socket table step length"
int "Configure socket table step length"

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个要修改下

Copy link

github-actions bot commented Sep 24, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/net/sal/Kconfig
  • components/net/sal/include/sal_socket.h
  • components/net/sal/src/sal_socket.c

📊 Current Review Status (Last Updated: 2025-09-24 20:06 CST)

  • Maihuanyi Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@RT-Thread RT-Thread deleted a comment from github-actions bot Sep 24, 2025

#define VALID_PROTOCOL(protocol) ((protocol) >= 0 && (protocol) <= IPPROTO_RAW)
#define VALID_COMBO(domain, type, protocol) \
( \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块代码建议格式化下,参考这块的风格:PR

Comment on lines +17 to +20
#include "sal_low_lvl.h"
#include "sal_msg.h"
#include "sal_netdb.h"
#include "sal_tls.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不推荐加到这里,交给用户加吧,其他的文件也是这么干的:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants