wireless/wapi: Return -errno in all fail path
to avoid some return -1, otheer return -errno Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
a06e53b1f9
commit
c45a7c8ccd
@ -95,7 +95,7 @@ int wpa_driver_wext_get_key_ext(int sockfd, FAR const char *ifname,
|
||||
ext = malloc(sizeof(*ext) + *req_len);
|
||||
if (ext == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
@ -127,7 +127,7 @@ int wpa_driver_wext_get_key_ext(int sockfd, FAR const char *ifname,
|
||||
|
||||
default:
|
||||
free(ext);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (key && ext->key_len < *req_len)
|
||||
@ -167,7 +167,7 @@ int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname,
|
||||
ext = malloc(sizeof(*ext) + key_len);
|
||||
if (ext == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
@ -203,12 +203,12 @@ int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname,
|
||||
default:
|
||||
nerr("ERROR: Unknown algorithm %d", alg);
|
||||
free(ext);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ioctl(sockfd, SIOCSIWENCODEEXT, (unsigned long)&iwr) < 0)
|
||||
{
|
||||
ret = errno == EOPNOTSUPP ? -2 : -1;
|
||||
ret = -errno;
|
||||
nerr("ERROR: ioctl[SIOCSIWENCODEEXT]: %d", errno);
|
||||
}
|
||||
|
||||
@ -369,7 +369,7 @@ static int wpa_driver_wext_process_auth_param(int sockfd,
|
||||
idx, *value, errcode);
|
||||
}
|
||||
|
||||
ret = errcode == EOPNOTSUPP ? -2 : -1;
|
||||
ret = -errcode;
|
||||
}
|
||||
|
||||
if (ret == 0 && !set)
|
||||
|
@ -190,7 +190,8 @@ static bool wapi_json_update(FAR cJSON *root,
|
||||
|
||||
int wapi_make_socket(void)
|
||||
{
|
||||
return socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
|
||||
int fd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
|
||||
return fd < 0 ? -errno : fd;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -441,13 +442,13 @@ int wapi_save_config(FAR const char *ifname,
|
||||
FAR char *buf = NULL;
|
||||
FAR cJSON *ifobj;
|
||||
FAR cJSON *root;
|
||||
int ret = -1;
|
||||
int ret = -ENOMEM;
|
||||
int fd = -1;
|
||||
bool update;
|
||||
|
||||
if (ifname == NULL || conf == NULL)
|
||||
{
|
||||
return ret;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (confname == NULL)
|
||||
@ -507,10 +508,15 @@ int wapi_save_config(FAR const char *ifname,
|
||||
fd = open(confname, O_RDWR | O_CREAT | O_TRUNC);
|
||||
if (fd < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = write(fd, buf, strlen(buf));
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
|
||||
errout:
|
||||
if (buf)
|
||||
|
@ -936,7 +936,7 @@ static int wapi_reconnect_cmd(int sock, int argc, FAR char **argv)
|
||||
load = wapi_load_config(argv[0], NULL, &conf);
|
||||
if (load == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = wpa_driver_wext_associate(&conf);
|
||||
@ -978,7 +978,7 @@ static int wapi_save_config_cmd(int sock, int argc, FAR char **argv)
|
||||
|
||||
if (!IFF_IS_RUNNING(if_flags))
|
||||
{
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
psk_len = sizeof(psk);
|
||||
|
@ -219,7 +219,7 @@ static int wapi_parse_mode(int iw_mode, FAR enum wapi_mode_e *wapi_mode)
|
||||
|
||||
default:
|
||||
WAPI_ERROR("ERROR: Unknown mode: %d\n", iw_mode);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ static void wapi_event_stream_init(FAR struct wapi_event_stream_s *stream,
|
||||
static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream,
|
||||
FAR struct iw_event *iwe)
|
||||
{
|
||||
int ret;
|
||||
int ret = 1;
|
||||
FAR struct iw_event *iwe_stream;
|
||||
|
||||
if (stream->current + offsetof(struct iw_event, u) > stream->end)
|
||||
@ -279,11 +279,9 @@ static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream,
|
||||
if (stream->current + iwe_stream->len > stream->end ||
|
||||
iwe_stream->len < offsetof(struct iw_event, u))
|
||||
{
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
switch (iwe_stream->cmd)
|
||||
{
|
||||
case SIOCGIWESSID:
|
||||
@ -348,7 +346,7 @@ static int wapi_scan_event(FAR struct iw_event *event,
|
||||
if (!temp)
|
||||
{
|
||||
WAPI_STRERROR("malloc()");
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Reset it. */
|
||||
@ -523,7 +521,7 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
|
||||
else
|
||||
{
|
||||
WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.freq.flags);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Set freq. */
|
||||
@ -983,7 +981,7 @@ int wapi_get_bitrate(int sock, FAR const char *ifname,
|
||||
if (wrq.u.bitrate.disabled)
|
||||
{
|
||||
WAPI_ERROR("ERROR: Bitrate is disabled\n");
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get bitrate. */
|
||||
@ -1087,7 +1085,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
|
||||
|
||||
if (wrq.u.txpower.disabled)
|
||||
{
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get flag. */
|
||||
@ -1106,7 +1104,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
|
||||
|
||||
default:
|
||||
WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.txpower.flags);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get power. */
|
||||
@ -1321,7 +1319,7 @@ int wapi_scan_coll(int sock, FAR const char *ifname,
|
||||
if (!buf)
|
||||
{
|
||||
WAPI_STRERROR("malloc()");
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
alloc:
|
||||
@ -1344,7 +1342,7 @@ alloc:
|
||||
{
|
||||
WAPI_STRERROR("realloc()");
|
||||
free(buf);
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
buf = tmp;
|
||||
|
Loading…
Reference in New Issue
Block a user