Change in libosmocore[master]: gprs_ns2: unify the handling of **result when bind already present.

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Feb 3 13:55:05 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22644 )

Change subject: gprs_ns2: unify the handling of **result when bind already present.
......................................................................

gprs_ns2: unify the handling of **result when bind already present.

All bind function should work in the same way.
Also fixing a null pointer assignment if no **result is giving.

Change-Id: Idd0c2190d2af39804c18c4786a997079db9a4330
---
M src/gb/gprs_ns2_fr.c
M src/gb/gprs_ns2_frgre.c
M src/gb/gprs_ns2_udp.c
3 files changed, 15 insertions(+), 9 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index fc6a5c4..f1a5576 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -721,8 +721,8 @@
  *  \param[in] netif Network interface to bind to
  *  \param[in] fr_network
  *  \param[in] fr_role
- *  \param[out] result pointer to created bind
- *  \return 0 on success; negative on error */
+ *  \param[out] result pointer to the created bind or if a bind with the name exists return the bind.
+ *  \return 0 on success; negative on error. -EALREADY returned in case a bind with the name exists */
 int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
 		     const char *name,
 		     const char *netif,
@@ -738,8 +738,12 @@
 	if (strlen(netif) > IFNAMSIZ)
 		return -EINVAL;
 
-	if (gprs_ns2_bind_by_name(nsi, name))
+	bind = gprs_ns2_bind_by_name(nsi, name);
+	if (bind) {
+		if (result)
+			*result = bind;
 		return -EALREADY;
+	}
 
 	rc = ns2_bind_alloc(nsi, name, &bind);
 	if (rc < 0)
diff --git a/src/gb/gprs_ns2_frgre.c b/src/gb/gprs_ns2_frgre.c
index 88ef037..853375d 100644
--- a/src/gb/gprs_ns2_frgre.c
+++ b/src/gb/gprs_ns2_frgre.c
@@ -529,8 +529,8 @@
  *  \param[in] nsi NS instance in which to create the bind
  *  \param[in] local local address on which to bind
  *  \param[in] dscp DSCP/TOS bits to use for transmitted data on this bind
- *  \param[out] result pointer to created bind
- *  \return 0 on success; negative on error */
+ *  \param[out] result pointer to the created bind or if a bind with the name exists return the bind.
+ *  \return 0 on success; negative on error. -EALREADY returned in case a bind with the name exists */
 int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
 			const char *name,
 			const struct osmo_sockaddr *local,
@@ -546,7 +546,8 @@
 
 	bind = gprs_ns2_bind_by_name(nsi, name);
 	if (bind) {
-		*result = bind;
+		if (result)
+			*result = bind;
 		return -EALREADY;
 	}
 
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 9277f9a..e07f6d4 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -303,8 +303,8 @@
  *  \param[in] nsi NS Instance in which to create the NSVC
  *  \param[in] local the local address to bind to
  *  \param[in] dscp the DSCP/TOS bits used for transmitted data
- *  \param[out] result if set, returns the bind object
- *  \return 0 on success; negative in case of error */
+ *  \param[out] result pointer to the created bind or if a bind with the name exists return the bind.
+ *  \return 0 on success; negative on error. -EALREADY returned in case a bind with the name exists */
 int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
 		     const char *name,
 		     const struct osmo_sockaddr *local,
@@ -320,7 +320,8 @@
 
 	bind = gprs_ns2_ip_bind_by_sockaddr(nsi, local);
 	if (bind) {
-		*result = bind;
+		if (result)
+			*result = bind;
 		return -EBUSY;
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22644
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idd0c2190d2af39804c18c4786a997079db9a4330
Gerrit-Change-Number: 22644
Gerrit-PatchSet: 4
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210203/8c121a9f/attachment.htm>


More information about the gerrit-log mailing list