mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-30 07:42:23 +02:00
src: be more careful before dereferencing potentially NULL pointers
This commit is contained in:
17
src/at.c
17
src/at.c
@@ -52,7 +52,7 @@ static int configure_serial(const char *tty)
|
|||||||
static gboolean send_at_command(struct EG25Manager *manager)
|
static gboolean send_at_command(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
char command[256];
|
char command[256];
|
||||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||||
|
|
||||||
if (at_cmd) {
|
if (at_cmd) {
|
||||||
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
||||||
@@ -88,7 +88,10 @@ static gboolean send_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void next_at_command(struct EG25Manager *manager)
|
static void next_at_command(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||||
|
|
||||||
|
if (!at_cmd)
|
||||||
|
return;
|
||||||
|
|
||||||
if (at_cmd->cmd)
|
if (at_cmd->cmd)
|
||||||
g_free(at_cmd->cmd);
|
g_free(at_cmd->cmd);
|
||||||
@@ -106,7 +109,10 @@ static void next_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void retry_at_command(struct EG25Manager *manager)
|
static void retry_at_command(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||||
|
|
||||||
|
if (!at_cmd)
|
||||||
|
return;
|
||||||
|
|
||||||
at_cmd->retries++;
|
at_cmd->retries++;
|
||||||
if (at_cmd->retries > 3) {
|
if (at_cmd->retries > 3) {
|
||||||
@@ -119,7 +125,10 @@ static void retry_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void process_at_result(struct EG25Manager *manager, char *response)
|
static void process_at_result(struct EG25Manager *manager, char *response)
|
||||||
{
|
{
|
||||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||||
|
|
||||||
|
if (!at_cmd)
|
||||||
|
return;
|
||||||
|
|
||||||
if (at_cmd->expected && !strstr(response, at_cmd->expected)) {
|
if (at_cmd->expected && !strstr(response, at_cmd->expected)) {
|
||||||
if (at_cmd->value)
|
if (at_cmd->value)
|
||||||
|
@@ -177,7 +177,7 @@ gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
|
|||||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||||
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
||||||
|
|
||||||
if (keep_down) {
|
if (keep_down && manager->gpio_out[GPIO_OUT_RESET]) {
|
||||||
// Asserting RESET line to prevent modem from rebooting
|
// Asserting RESET line to prevent modem from rebooting
|
||||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user