Prefer sbuf_new_for_sysctl() over error-prone manually managed buf.
No functional change intended.
MFC after: 1 week
Differential D48496
bnxt_en: Improve sysctl handler bnxt_dcb_list_app() zlei on Jan 17 2025, 11:24 AM. Authored by Tags None Referenced Files
Subscribers None
Details Prefer sbuf_new_for_sysctl() over error-prone manually managed buf. No functional change intended. MFC after: 1 week
Diff Detail
Event TimelineComment Actions I'm not sure if this helps 284073 but it appears that the buf is unlikely to overflow.
Comment Actions Prefer sbuf_new_for_sysctl(), and calculate the buf size according to num of apps. After a carefully calculating, with maximum apps, i.e. 128 apps, the 4096 bytes buf is still not sufficent. A hand crafted test shows that it requires about 5907 bytes. To make the buf aligned, choose 64 bytes per app. Ideally I want a sbuf_new_for_sysctl_flag() which can pass in SBUF_AUTOEXTEND. That will be much more flexible, but probably not in this context. As that requires new KPI. User may request ERRTA fix in releng branch so just use sbuf_new_for_sysctl() right now. Comment Actions Note that sbuf_new_for_sysctl() creates a stream: the sbuf has a drain function, sbuf_sysctl_drain(), which uses SYSCTL_OUT to copy out the buffer, so once the buffer is full, sbuf_putc() can drain the buffer and keep going. So, the buffer size is not too important, and SBUF_AUTOEXTEND shouldn't be needed. Comment Actions Ahh, you're right ! I only looked into sbuf_finish() but not sbuf_printf(). So a small buffer is OK for sbuf_new_for_sysctl(). I'm going to choose a buffer size, say 128. Does that look good to you ? Comment Actions I think that's fine, the buffer size is mostly arbitrary in this case. 128 bytes should work. |