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/.
Max gerrit-no-reply at lists.osmocom.orgMax has submitted this change and it was merged.
Change subject: lc15: cleanup board parameters reading
......................................................................
lc15: cleanup board parameters reading
* move common code into separate function
* print error similar to parameter reading code
Change-Id: Icf3285d7bb921d212cb8945e835be2c81189fb87
Related: SYS#3728
---
M src/osmo-bts-litecell15/misc/lc15bts_bid.c
1 file changed, 25 insertions(+), 22 deletions(-)
Approvals:
Harald Welte: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_bid.c b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
index 06a126a..ba2037a 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_bid.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
@@ -24,12 +24,13 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include "lc15bts_bid.h"
#define BOARD_REV_SYSFS "/var/lc15/platform/revision"
#define BOARD_OPT_SYSFS "/var/lc15/platform/option"
-
+
static const int option_type_mask[_NUM_OPTION_TYPES] = {
[LC15BTS_OPTION_OCXO] = 0x07,
[LC15BTS_OPTION_FPGA] = 0x03,
@@ -72,6 +73,21 @@
static int board_rev = -1;
static int board_option = -1;
+static inline bool read_board(const char *src, const char *spec, void *dst)
+{
+ FILE *fp = fopen(src, "r");
+ if (!fp) {
+ fprintf(stderr, "Failed to open %s due to '%s' error\n", src, strerror(errno));
+ return false;
+ }
+
+ if (fscanf(fp, spec, dst) != 1) {
+ fclose(fp);
+ fprintf(stderr, "Failed to read %s due to '%s' error\n", src, strerror(errno));
+ return false;
+ }
+ fclose(fp);
+}
int lc15bts_rev_get(void)
{
@@ -82,14 +98,8 @@
return board_rev;
}
- fp = fopen(BOARD_REV_SYSFS, "r");
- if (fp == NULL) return -1;
-
- if (fscanf(fp, "%c", &rev) != 1) {
- fclose( fp );
- return -1;
- }
- fclose(fp);
+ if (!read_board(BOARD_REV_SYSFS, "%c", &rev))
+ return -1;
board_rev = rev;
return board_rev;
@@ -99,22 +109,15 @@
{
FILE *fp;
int opt;
+ bool rc;
+ if (board_option != -1)
+ return board_option;
- if (board_option == -1) {
- fp = fopen(BOARD_OPT_SYSFS, "r");
- if (fp == NULL) {
- return -1;
- }
-
- if (fscanf(fp, "%X", &opt) != 1) {
- fclose( fp );
- return -1;
- }
- fclose(fp);
+ if (!read_board(BOARD_OPT_SYSFS, "%X", &opt))
+ return -1;
- board_option = opt;
- }
+ board_option = opt;
return board_option;
}
--
To view, visit https://gerrit.osmocom.org/3268
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icf3285d7bb921d212cb8945e835be2c81189fb87
Gerrit-PatchSet: 2
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>