2019-12-01 16:25:36

by Daniel Almeida

[permalink] [raw]
Subject: [PATCH 2/6] media: dvb_dummy_fe: Add error messages in case of attach failure

From: "Daniel W. S. Almeida" <[email protected]>

Complain if the attach functions fail, for any reason. This is helpful
when debugging.

Suggested-by: Shuah Khan <[email protected]>
Signed-off-by: Daniel W. S. Almeida <[email protected]>
---
drivers/media/dvb-frontends/dvb_dummy_fe.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/dvb_dummy_fe.c b/drivers/media/dvb-frontends/dvb_dummy_fe.c
index 909dac2345c4..987c3488fe6c 100644
--- a/drivers/media/dvb-frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb-frontends/dvb_dummy_fe.c
@@ -114,12 +114,16 @@ struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
/* allocate memory for the internal state */
state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
if (!state)
- return NULL;
+ goto err;

/* create dvb_frontend */
memcpy(&state->frontend.ops, &dvb_dummy_fe_ofdm_ops, sizeof(struct dvb_frontend_ops));
state->frontend.demodulator_priv = state;
return &state->frontend;
+
+err:
+ pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
+ return NULL;
}
EXPORT_SYMBOL(dvb_dummy_fe_ofdm_attach);

@@ -132,12 +136,16 @@ struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
/* allocate memory for the internal state */
state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
if (!state)
- return NULL;
+ goto err;

/* create dvb_frontend */
memcpy(&state->frontend.ops, &dvb_dummy_fe_qpsk_ops, sizeof(struct dvb_frontend_ops));
state->frontend.demodulator_priv = state;
return &state->frontend;
+
+err:
+ pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
+ return NULL;
}
EXPORT_SYMBOL(dvb_dummy_fe_qpsk_attach);

@@ -150,12 +158,16 @@ struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
/* allocate memory for the internal state */
state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
if (!state)
- return NULL;
+ goto err;

/* create dvb_frontend */
memcpy(&state->frontend.ops, &dvb_dummy_fe_qam_ops, sizeof(struct dvb_frontend_ops));
state->frontend.demodulator_priv = state;
return &state->frontend;
+
+err:
+ pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
+ return NULL;
}
EXPORT_SYMBOL(dvb_dummy_fe_qam_attach);

--
2.24.0


2019-12-31 10:21:16

by Sean Young

[permalink] [raw]
Subject: Re: [PATCH 2/6] media: dvb_dummy_fe: Add error messages in case of attach failure

On Sun, Dec 01, 2019 at 01:15:38PM -0300, Daniel W. S. Almeida wrote:
> From: "Daniel W. S. Almeida" <[email protected]>
>
> Complain if the attach functions fail, for any reason. This is helpful
> when debugging.
>
> Suggested-by: Shuah Khan <[email protected]>
> Signed-off-by: Daniel W. S. Almeida <[email protected]>
> ---
> drivers/media/dvb-frontends/dvb_dummy_fe.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/dvb_dummy_fe.c b/drivers/media/dvb-frontends/dvb_dummy_fe.c
> index 909dac2345c4..987c3488fe6c 100644
> --- a/drivers/media/dvb-frontends/dvb_dummy_fe.c
> +++ b/drivers/media/dvb-frontends/dvb_dummy_fe.c
> @@ -114,12 +114,16 @@ struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
> /* allocate memory for the internal state */
> state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
> if (!state)
> - return NULL;
> + goto err;
>
> /* create dvb_frontend */
> memcpy(&state->frontend.ops, &dvb_dummy_fe_ofdm_ops, sizeof(struct dvb_frontend_ops));
> state->frontend.demodulator_priv = state;
> return &state->frontend;
> +
> +err:
> + pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
> + return NULL;

No need to log anything after k[zm]alloc() failures.

Thanks

Sean

> }
> EXPORT_SYMBOL(dvb_dummy_fe_ofdm_attach);
>
> @@ -132,12 +136,16 @@ struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
> /* allocate memory for the internal state */
> state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
> if (!state)
> - return NULL;
> + goto err;
>
> /* create dvb_frontend */
> memcpy(&state->frontend.ops, &dvb_dummy_fe_qpsk_ops, sizeof(struct dvb_frontend_ops));
> state->frontend.demodulator_priv = state;
> return &state->frontend;
> +
> +err:
> + pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
> + return NULL;
> }
> EXPORT_SYMBOL(dvb_dummy_fe_qpsk_attach);
>
> @@ -150,12 +158,16 @@ struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
> /* allocate memory for the internal state */
> state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
> if (!state)
> - return NULL;
> + goto err;
>
> /* create dvb_frontend */
> memcpy(&state->frontend.ops, &dvb_dummy_fe_qam_ops, sizeof(struct dvb_frontend_ops));
> state->frontend.demodulator_priv = state;
> return &state->frontend;
> +
> +err:
> + pr_err("%s: DVB Dummy frontend driver attach failed\n", __func__);
> + return NULL;
> }
> EXPORT_SYMBOL(dvb_dummy_fe_qam_attach);
>
> --
> 2.24.0