qmi: Remove redundant NULL check in qmi_param_new
PATCH 1/4 qmi: Remove redundant NULL check in qmi_param_new
l_new cannot fail, and thus cannot return NULL. Remove the check and simplify the code.
--- drivers/qmimodem/qmi.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/qmimodem/qmi.c +1 -7
@@ -2345,13 +2345,7 @@ struct qmi_device *qmi_device_new_qrtr(void)struct qmi_param *qmi_param_new (void ) { -struct qmi_param *param; - - param = l_new(struct qmi_param, 1); -if (!param) -return NULL ; - -return param; + return l_new(struct qmi_param, 1); }void qmi_param_free (struct qmi_param *param)
Signature · 1 line
2.44.0
PATCH 2/4 qmi: voicecall: Fix up code style violations
Fix up some style violations:
- > 80 character lines
- Redundant parenthesis
Also, while here, fix up a typo: "informations" -> "information"
--- drivers/qmimodem/voicecall.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/qmimodem/voicecall.c +8 -6
@@ -90,7 +90,7 @@ static bool ofono_call_match_by_id(const void *a, const void *b)const struct ofono_call *call = a;unsigned int id =L_PTR_TO_UINT (b); -return (call->id == id); +return call->id == id; }static bool ofono_call_match_by_status (const void *a,const void *b)
@@ -294,7 +294,7 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data) }if (!call_information->size) { -DBG ("No call informations received!" ); +DBG ("No call information received!" );return ; }
@@ -370,9 +370,11 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data) call->direction =qmi_to_ofono_direction (call_info.direction); call->type =0 ;/* always voice */ - number_size =MIN (remote_party->number_size,OFONO_MAX_PHONE_NUMBER_LENGTH ); + number_size =MIN (remote_party->number_size, +OFONO_MAX_PHONE_NUMBER_LENGTH ); tmp =l_strndup (remote_party->number, number_size); -l_strlcpy (call->phone_number.number, tmp,sizeof (call->phone_number.number)); +l_strlcpy (call->phone_number.number, tmp, +sizeof (call->phone_number.number));l_free (tmp);if (strlen (call->phone_number.number) >0 )
@@ -489,7 +491,8 @@ static void answer_cb(struct qmi_result *result, void *user_data)CALLBACK_WITH_SUCCESS (cb, cbd->data); } -static void answer (struct ofono_voicecall *vc,ofono_voicecall_cb_t cb,void *data) +static void answer (struct ofono_voicecall *vc, +ofono_voicecall_cb_t cb,void *data) {struct voicecall_data *vd =ofono_voicecall_get_data (vc);struct cb_data *cbd;
@@ -679,4 +682,3 @@ static const struct ofono_voicecall_driver driver = { };OFONO_ATOM_DRIVER_BUILTIN (voicecall, qmimodem, &driver) -
Signature · 1 line
2.44.0
PATCH 3/4 qmi: voicecall: Remove ternary conditional use
In reply to Denis KenziorSimplify the code a bit by removing the use of ternary conditional operation and replace it with a 'remote_number_tlv' variable. This also removed a slight coding violation where a mix of spaces and tabs was used for indentation.
--- drivers/qmimodem/voicecall.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/qmimodem/voicecall.c +4 -7
@@ -263,7 +263,6 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data)int i;int offset;uint16_t len; -bool status = true;int instance_size;const struct qmi_voice_call_information *call_information;const struct qmi_voice_remote_party_number *remote_party_number;
@@ -275,6 +274,8 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data)static const uint8_t RESULT_CALL_INFO_CALL_INFORMATION =0x10 ;static const uint8_t RESULT_CALL_INFO_REMOTE_NUMBER =0x11 ; +uint8_t remote_number_tlv =RESULT_CALL_STATUS_REMOTE_NUMBER ; +DBG ("" );/* mandatory */
@@ -285,7 +286,7 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data) call_information =qmi_result_get ( result,RESULT_CALL_INFO_CALL_INFORMATION , &len); - status = false; + remote_number_tlv =RESULT_CALL_INFO_REMOTE_NUMBER ; }if (!call_information || len <sizeof (call_information->size)) {
@@ -306,11 +307,7 @@ static void all_call_status_ind(struct qmi_result *result, void *user_data) }/* mandatory */ - remote_party_number =qmi_result_get ( - result, - status ?RESULT_CALL_STATUS_REMOTE_NUMBER : -RESULT_CALL_INFO_REMOTE_NUMBER , - &len); + remote_party_number =qmi_result_get (result, remote_number_tlv, &len);if (!remote_party_number) {DBG ("Unable to retrieve remote numbers" );
Signature · 1 line
2.44.0
PATCH 4/4 qmi: voicecall: Remove redundant initialization to NULL
In reply to Denis Kenziorparam was needlelly initialized to NULL in answer() and release_specific(). Since all error paths free both cbd and param, declare & initialize these variables at the start of the function.
Handle dial() similarly for consistency.
--- drivers/qmimodem/voicecall.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/qmimodem/voicecall.c +12 -20
@@ -434,7 +434,8 @@ static void dial(struct ofono_voicecall *vc, {struct voicecall_data *vd =ofono_voicecall_get_data (vc);struct cb_data *cbd =cb_data_new (cb, data); -struct qmi_param *param; +struct qmi_param *param =qmi_param_new (); +const char *calling_number =phone_number_to_string (ph);static const uint8_t PARAM_CALL_NUMBER =0x01 ;
@@ -446,8 +447,6 @@ static void dial(struct ofono_voicecall *vc, cbd->user = vc;memcpy (&vd->dialed, ph,sizeof (*ph)); - param =qmi_param_new (); -if (!qmi_param_append (param,PARAM_CALL_NUMBER ,strlen (calling_number), calling_number)) goto error;
@@ -492,27 +491,22 @@ static void answer(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb, void *data) { struct voicecall_data *vd = ofono_voicecall_get_data(vc); -struct cb_data *cbd; +struct cb_data *cbd =cb_data_new (cb, data); +struct qmi_param *param =qmi_param_new ();struct ofono_call *call; -struct qmi_param *param =NULL ; -static const uint8_t PARAM_CALL_ID =0x01 ;DBG ("" ); - call =l_queue_find (vd->call_list, - ofono_call_match_by_status, -L_UINT_TO_PTR (CALL_STATUS_INCOMING )); - - param =qmi_param_new (); - cbd =cb_data_new (cb, data); - cbd->user = vc; - -if (call ==NULL ) { + call =l_queue_find (vd->call_list, ofono_call_match_by_status, +L_UINT_TO_PTR (CALL_STATUS_INCOMING )); +if (!call) {ofono_error ("Can not find a call to pick up" ); goto error; } + cbd->user = vc; +if (!qmi_param_append_uint8 (param,PARAM_CALL_ID , call->id)) goto error;
@@ -552,22 +546,20 @@ static void release_specific(struct ofono_voicecall *vc, int id, ofono_voicecall_cb_t cb, void *data) { struct voicecall_data *vd = ofono_voicecall_get_data(vc); -struct cb_data *cbd; -struct qmi_param *param =NULL ; +struct cb_data *cbd =cb_data_new (cb, data); +struct qmi_param *param =qmi_param_new ();static const uint8_t PARAM_CALL_ID =0x01 ;DBG ("" ); - param =qmi_param_new (); - cbd =cb_data_new (cb, data); cbd->user = vc;if (!qmi_param_append_uint8 (param,PARAM_CALL_ID , id)) goto error;if (qmi_service_send (vd->voice,QMI_VOICE_END_CALL , param, end_call_cb, - cbd, l_free) >0 ) + cbd, l_free) >0 )return ; error:
Signature · 1 line
2.44.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 5 lines · On Mon, 22 Apr 2024 16:40:43 -0500 you wrote:
l_newcannot fail, and thus cannot return NULL. Remove the check and simplify the code.--- drivers/qmimodem/qmi.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
Here is the summary with links:
- [1/4] qmi: Remove redundant NULL check in qmi_param_new
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=e16edbd2bb51 - [2/4] qmi: voicecall: Fix up code style violations https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=3c5ed8ec1e57 - [3/4] qmi: voicecall: Remove ternary conditional use https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=231cde4f12a4 - [4/4] qmi: voicecall: Remove redundant initialization to NULL https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=789f68a5fba3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html