Refactor range encoding

Submitted by msuraev@sysmocom.de on April 18, 2016, 9:21 a.m.

Details

Message ID 1460971300-14579-1-git-send-email-msuraev@sysmocom.de
State New
Series "Refactor range encoding"
Headers show

Commit Message

msuraev@sysmocom.de April 18, 2016, 9:21 a.m.
From: Max <msuraev@sysmocom.de>

Convert functions always returning the same constant into void
type. Remove useless check of return value.
---
 openbsc/include/openbsc/arfcn_range_encode.h | 10 +++++-----
 openbsc/src/libbsc/arfcn_range_encode.c      | 19 +++++++------------
 openbsc/src/libbsc/system_information.c      | 22 ++++++++++------------
 openbsc/tests/gsm0408/gsm0408_test.c         | 24 +++++++-----------------
 4 files changed, 29 insertions(+), 46 deletions(-)

Patch hide | download patch | download mbox

diff --git a/openbsc/include/openbsc/arfcn_range_encode.h b/openbsc/include/openbsc/arfcn_range_encode.h
index bd85d6a..7992c70 100644
--- a/openbsc/include/openbsc/arfcn_range_encode.h
+++ b/openbsc/include/openbsc/arfcn_range_encode.h
@@ -14,13 +14,13 @@  enum {
 #define RANGE_ENC_MAX_ARFCNS	29
 
 int range_enc_determine_range(const int *arfcns, int size, int *f0_out);
-int range_enc_arfcns(const int rng, const int *arfcns, int sze, int *out, int idx);
+void range_enc_arfcns(const int rng, const int *arfcns, int sze, int *out, int idx);
 int range_enc_find_index(const int rng, const int *arfcns, int size);
 int range_enc_filter_arfcns(int *arfcns, const int sze, const int f0, int *f0_included);
 
-int range_enc_range128(uint8_t *chan_list, int f0, int *w);
-int range_enc_range256(uint8_t *chan_list, int f0, int *w);
-int range_enc_range512(uint8_t *chan_list, int f0, int *w);
-int range_enc_range1024(uint8_t *chan_list, int f0, int f0_incl, int *w);
+void range_enc_range128(uint8_t *chan_list, int f0, int *w);
+void range_enc_range256(uint8_t *chan_list, int f0, int *w);
+void range_enc_range512(uint8_t *chan_list, int f0, int *w);
+void range_enc_range1024(uint8_t *chan_list, int f0, int f0_incl, int *w);
 
 #endif
diff --git a/openbsc/src/libbsc/arfcn_range_encode.c b/openbsc/src/libbsc/arfcn_range_encode.c
index e67bf0a..31fb8b8 100644
--- a/openbsc/src/libbsc/arfcn_range_encode.c
+++ b/openbsc/src/libbsc/arfcn_range_encode.c
@@ -79,7 +79,7 @@  int range_enc_find_index(const int range, const int *freqs, const int size)
  * \param size The size of the list of ARFCNs
  * \param out Place to store the W(i) output.
  */
-int range_enc_arfcns(const int range,
+void range_enc_arfcns(const int range,
 		const int *arfcns, int size, int *out,
 		const int index)
 {
@@ -100,11 +100,11 @@  int range_enc_arfcns(const int range,
 
 	/* Test the two recursion anchors and stop processing */
 	if (size == 0)
-		return 0;
+		return;
 
 	if (size == 1) {
 		out[index] = 1 + arfcns[0];
-		return 0;
+		return;
 	}
 
 	/* Now do the processing */
@@ -131,7 +131,6 @@  int range_enc_arfcns(const int range,
 			out, index + greatest_power_of_2_lesser_or_equal_to(index + 1));
 	range_enc_arfcns((range -1 ) / 2, arfcns_right, r_size,
 			 out, index + (2 * greatest_power_of_2_lesser_or_equal_to(index + 1)));
-	return 0;
 }
 
 /*
@@ -265,39 +264,35 @@  static void write_all_wn(uint8_t *chan_list, int bit_offs,
 	}
 }
 
-int range_enc_range128(uint8_t *chan_list, int f0, int *w)
+void range_enc_range128(uint8_t *chan_list, int f0, int *w)
 {
 	chan_list[0] = 0x8C;
 	write_orig_arfcn(chan_list, f0);
 
 	write_all_wn(&chan_list[2], 1, w, 28, 7);
-	return 0;
 }
 
-int range_enc_range256(uint8_t *chan_list, int f0, int *w)
+void range_enc_range256(uint8_t *chan_list, int f0, int *w)
 {
 	chan_list[0] = 0x8A;
 	write_orig_arfcn(chan_list, f0);
 
 	write_all_wn(&chan_list[2], 1, w, 21, 8);
-	return 0;
 }
 
-int range_enc_range512(uint8_t *chan_list, int f0, int *w)
+void range_enc_range512(uint8_t *chan_list, int f0, int *w)
 {
 	chan_list[0] = 0x88;
 	write_orig_arfcn(chan_list, f0);
 
 	write_all_wn(&chan_list[2], 1, w, 17, 9);
-	return 0;
 }
 
-int range_enc_range1024(uint8_t *chan_list, int f0, int f0_included, int *w)
+void range_enc_range1024(uint8_t *chan_list, int f0, int f0_included, int *w)
 {
 	chan_list[0] = 0x80 | (f0_included << 2);
 
 	write_all_wn(&chan_list[0], 6, w, 16, 10);
-	return 0;
 }
 
 int range_enc_filter_arfcns(int *arfcns,
diff --git a/openbsc/src/libbsc/system_information.c b/openbsc/src/libbsc/system_information.c
index 43a492a..da36652 100644
--- a/openbsc/src/libbsc/system_information.c
+++ b/openbsc/src/libbsc/system_information.c
@@ -173,7 +173,7 @@  static inline int enc_freq_lst_range(uint8_t *chan_list,
 	int w[RANGE_ENC_MAX_ARFCNS];
 	int f0_included = 0;
 	int arfcns_used = 0;
-	int i, rc, range, f0;
+	int i, range, f0;
 
 	/*
 	 * Select ARFCNs according to the rules in bitvec2freq_list
@@ -202,24 +202,22 @@  static inline int enc_freq_lst_range(uint8_t *chan_list,
 				f0, &f0_included);
 
 	memset(w, 0, sizeof(w));
-	rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
-	if (rc != 0)
-		return -3;
+	range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
 
 	/* Select the range and the amount of bits needed */
 	switch (range) {
 	case ARFCN_RANGE_128:
-		return range_enc_range128(chan_list, f0, w);
-		break;
+		range_enc_range128(chan_list, f0, w);
+		return 0;
 	case ARFCN_RANGE_256:
-		return range_enc_range256(chan_list, f0, w);
-		break;
+		range_enc_range256(chan_list, f0, w);
+		return 0;
 	case ARFCN_RANGE_512:
-		return range_enc_range512(chan_list, f0, w);
-		break;
+		range_enc_range512(chan_list, f0, w);
+		return 0;
 	case ARFCN_RANGE_1024:
-		return range_enc_range1024(chan_list, f0, f0_included, w);
-		break;
+		range_enc_range1024(chan_list, f0, f0_included, w);
+		return 0;
 	default:
 		return -4;
 	};
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index d6abce6..f0992f0 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -230,11 +230,7 @@  static int test_single_range_encoding(int range, const int *orig_arfcns,
 					      f0, &f0_included);
 
 	memset(w, 0, sizeof(w));
-	rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
-	if (rc != 0) {
-		printf("Cannot compute range W(k), rc = %d\n", rc);
-		return 1;
-	}
+	range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
 
 	if (!silent)
 		fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n",
@@ -243,24 +239,20 @@  static int test_single_range_encoding(int range, const int *orig_arfcns,
 	/* Select the range and the amount of bits needed */
 	switch (range) {
 	case ARFCN_RANGE_128:
-		rc = range_enc_range128(chan_list, f0, w);
+		range_enc_range128(chan_list, f0, w);
 		break;
 	case ARFCN_RANGE_256:
-		rc = range_enc_range256(chan_list, f0, w);
+		range_enc_range256(chan_list, f0, w);
 		break;
 	case ARFCN_RANGE_512:
-		rc = range_enc_range512(chan_list, f0, w);
+		range_enc_range512(chan_list, f0, w);
 		break;
 	case ARFCN_RANGE_1024:
-		rc = range_enc_range1024(chan_list, f0, f0_included, w);
+		range_enc_range1024(chan_list, f0, f0_included, w);
 		break;
 	default:
 		return 1;
 	};
-	if (rc != 0) {
-		printf("Cannot encode range, rc = %d\n", rc);
-		return 1;
-	}
 
 	if (!silent)
 		printf("chan_list = %s\n",
@@ -471,8 +463,7 @@  static void test_print_encoding()
 			break;
 		}
 
-	rc = range_enc_range512(chan_list, (1 << 9) | 0x96, w);
-	VERIFY(rc, ==, 0);
+	range_enc_range512(chan_list, (1 << 9) | 0x96, w);
 
 	printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list)));
 }
@@ -496,8 +487,7 @@  static void test_si_range_helpers()
 	printf("Element is: %d => freqs[i] = %d\n", i,  i >= 0 ? freqs3[i] : -1);
 	VERIFY(i, ==, 0);
 
-	i = range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
-	VERIFY(i, ==, 0);
+	range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
 
 	for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) {
 		printf("w[%d]=%d\n", i, ws[i]);