[PATCH 2/3] make phy name const to signify it's static nature

Leon M. Busch-George leon at georgemail.de
Fri Mar 1 15:16:21 PST 2024


From: "Leon M. Busch-George" <leon at georgemail.eu>

Typically, returning a char * signifies to callers that they own the buffer.

Signed-off-by: Leon M. Busch-George <leon at georgemail.eu>
---
 iwinfo_nl80211.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 2ea5925..8eab671 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -776,7 +776,7 @@ static int nl80211_phyname_cb(struct nl_msg *msg, void *arg)
 	return NL_SKIP;
 }
 
-static char * nl80211_ifname2phy(const char *ifname)
+static const char * nl80211_ifname2phy(const char *ifname)
 {
 	static char phy[PHY_NAME_BUFFER_SIZE] = { 0 };
 
@@ -788,7 +788,7 @@ static char * nl80211_ifname2phy(const char *ifname)
 	return (phy[0] && !phy[sizeof(phy) - 1]) ? phy : NULL;
 }
 
-static char * nl80211_phyidx2name(unsigned int idx)
+static const char * nl80211_phyidx2name(unsigned int idx)
 {
 	struct nl80211_msg_conveyor *cv;
 	static char phy[PHY_NAME_BUFFER_SIZE] = { 0 };
@@ -907,7 +907,8 @@ static int nl80211_get_mode(const char *ifname, int *buf)
 static int __nl80211_hostapd_query(const char *ifname, ...)
 {
 	va_list ap, ap_cur;
-	char *phy, *search, *dest, *key, *val, buf[128];
+	const char *phy;
+	char *search, *dest, *key, *val, buf[128];
 	int len, mode, found = 0, match = 1;
 	FILE *fp;
 
@@ -1204,7 +1205,7 @@ static void nl80211_hostapd_hup(const char *ifname)
 {
 	int fd, pid = 0;
 	char buf[32];
-	char *phy = nl80211_ifname2phy(ifname);
+	const char *phy = nl80211_ifname2phy(ifname);
 
 	if (phy)
 	{
@@ -3486,7 +3487,8 @@ static int nl80211_get_mbssid_support(const char *ifname, int *buf)
 
 static int nl80211_hardware_id_from_fdt(struct iwinfo_hardware_id *id, const char *ifname)
 {
-	char *phy, path[PATH_MAX];
+	const char *phy;
+	char path[PATH_MAX];
 
 	/* Try to determine the phy name from the given interface */
 	phy = nl80211_ifname2phy(ifname);
@@ -3504,7 +3506,8 @@ static int nl80211_hardware_id_from_fdt(struct iwinfo_hardware_id *id, const cha
 static int nl80211_get_hardware_id(const char *ifname, char *buf)
 {
 	struct iwinfo_hardware_id *id = (struct iwinfo_hardware_id *)buf;
-	char *phy, num[8], path[PATH_MAX];
+	const char *phy;
+	char num[8], path[PATH_MAX];
 	int i;
 
 	struct { const char *path; uint16_t *dest; } lookup[] = {
-- 
2.44.0




More information about the openwrt-devel mailing list