From: Chanwoo Choi <cw00.choi@samsung.com>
To: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Cc: myungjoo.ham@samsung.com, sameo@linux.intel.com,
lee.jones@linaro.org, patches@opensource.wolfsonmicro.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 7/7] extcon: arizona: Improve headphone detection error handling
Date: Fri, 15 Nov 2013 09:54:01 +0900 [thread overview]
Message-ID: <528570A9.1070109@samsung.com> (raw)
In-Reply-To: <1384445907-12859-7-git-send-email-ckeepax@opensource.wolfsonmicro.com>
Hi Charles,
On 11/15/2013 01:18 AM, Charles Keepax wrote:
> In several places the return value of regmap operations is not checked
> whilst handling headphone detection. This patch adds checks for these
> return values. Additionally, failing to read/write a register is a
> serious enough error we should abort the headphone detection process so
> correct a couple of cases where this was not the case.
>
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> ---
> drivers/extcon/extcon-arizona.c | 82 ++++++++++++++++++++++++++++----------
> 1 files changed, 60 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
> index d71a738..321dcc9 100644
> --- a/drivers/extcon/extcon-arizona.c
> +++ b/drivers/extcon/extcon-arizona.c
> @@ -399,22 +399,32 @@ static int arizona_hpdet_read_ip1(struct arizona_extcon_info *info)
> ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
> if (ret != 0) {
I prefer following checking statement
if (ret < 0) instead of if (ret != 0)
> dev_err(arizona->dev, "Failed to read HP value: %d\n", ret);
> - return -EAGAIN;
> + return ret;
> }
>
> - regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, &range);
> + ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, &range);
> range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
> >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
I prefer to move 'range operation' statement after checking ret value.
> + if (ret != 0) {
ditto.
> + dev_err(arizona->dev, "Failed to read HP range: %d\n", ret);
> + return ret;
> + }
>
> if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
> (val < 100 || val >= 0x3fb)) {
> range++;
> dev_dbg(arizona->dev, "Moving to HPDET range %d\n", range);
> - regmap_update_bits(arizona->regmap,
> - ARIZONA_HEADPHONE_DETECT_1,
> - ARIZONA_HP_IMPEDANCE_RANGE_MASK,
> - range <<
> - ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
> + ret = regmap_update_bits(arizona->regmap,
> + ARIZONA_HEADPHONE_DETECT_1,
> + ARIZONA_HP_IMPEDANCE_RANGE_MASK,
> + range <<
> + ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
> + if (ret != 0) {
ditto.
> + dev_err(arizona->dev,
> + "Failed to move range (%d): %d\n",
> + range, ret);
> + return ret;
> + }
> return -EAGAIN;
If below statement is true, arizona_hpdet_read_ip1 always return error?
This if statement return either 'ret' or '-EAGAIN'.
if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
(val < 100 || val >= 0x3fb)) {
> }
>
> @@ -454,7 +464,11 @@ static int arizona_hpdet_read_ip2(struct arizona_extcon_info *info)
> /* Convert to ohms, the value is in 0.5 ohm increments */
> val /= 2;
>
> - regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, &range);
> + ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, &range);
> + if (ret != 0) {
ditto.
> + dev_err(arizona->dev, "Failed to read HP range: %d\n", ret);
> + return ret;
> + }
> range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
> >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
>
> @@ -465,11 +479,17 @@ static int arizona_hpdet_read_ip2(struct arizona_extcon_info *info)
> dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
> arizona_hpdet_c_ranges[range].min,
> arizona_hpdet_c_ranges[range].max);
> - regmap_update_bits(arizona->regmap,
> + ret = regmap_update_bits(arizona->regmap,
> ARIZONA_HEADPHONE_DETECT_1,
> ARIZONA_HP_IMPEDANCE_RANGE_MASK,
> range <<
> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
> + if (ret != 0) {
ditto.
> + dev_err(arizona->dev,
> + "Failed to move range (%d): %d\n",
> + range, ret);
> + return ret;
> + }
> return -EAGAIN;
ditto.
> }
>
> @@ -519,6 +539,7 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
> {
> struct arizona *arizona = info->arizona;
> int id_gpio = arizona->pdata.hpdet_id_gpio;
> + int ret;
>
> /*
> * If we're using HPDET for accessory identification we need
> @@ -531,18 +552,30 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
> if (id_gpio && info->num_hpdet_res == 1) {
> dev_dbg(arizona->dev, "Measuring mic\n");
>
> - regmap_update_bits(arizona->regmap,
> - ARIZONA_ACCESSORY_DETECT_MODE_1,
> - ARIZONA_ACCDET_MODE_MASK |
> - ARIZONA_ACCDET_SRC,
> - ARIZONA_ACCDET_MODE_HPR |
> - info->micd_modes[0].src);
> + ret = regmap_update_bits(arizona->regmap,
> + ARIZONA_ACCESSORY_DETECT_MODE_1,
> + ARIZONA_ACCDET_MODE_MASK |
> + ARIZONA_ACCDET_SRC,
> + ARIZONA_ACCDET_MODE_HPR |
> + info->micd_modes[0].src);
> + if (ret != 0) {
> + dev_err(arizona->dev,
> + "Failed to change HPDET source: %d\n",
> + ret);
> + return ret;
> + }
>
> gpio_set_value_cansleep(id_gpio, 1);
>
> - regmap_update_bits(arizona->regmap,
> - ARIZONA_HEADPHONE_DETECT_1,
> - ARIZONA_HP_POLL, ARIZONA_HP_POLL);
> + ret = regmap_update_bits(arizona->regmap,
> + ARIZONA_HEADPHONE_DETECT_1,
> + ARIZONA_HP_POLL, ARIZONA_HP_POLL);
> + if (ret != 0) {
> + dev_err(arizona->dev,
> + "Failed to re-enable HPDET: %d\n",
> + ret);
> + return ret;
> + }
> return -EAGAIN;
Always return error?
> }
>
> @@ -575,10 +608,15 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
> }
>
> /* Make sure everything is reset back to the real polarity */
> - regmap_update_bits(arizona->regmap,
> - ARIZONA_ACCESSORY_DETECT_MODE_1,
> - ARIZONA_ACCDET_SRC,
> - info->micd_modes[0].src);
> + ret = regmap_update_bits(arizona->regmap,
> + ARIZONA_ACCESSORY_DETECT_MODE_1,
> + ARIZONA_ACCDET_SRC,
> + info->micd_modes[0].src);
> + if (ret != 0) {
ditto.
> + dev_err(arizona->dev, "Failed to reset polarity: %d\n",
> + ret);
> + return ret;
> + }
> }
>
> return 0;
>
Thanks,
Chanwoo Choi
next prev parent reply other threads:[~2013-11-15 0:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-14 16:18 [PATCH v3 1/7] extcon: arizona: Add defines for microphone detection levels Charles Keepax
2013-11-14 16:18 ` [PATCH v3 2/7] extcon: arizona: Fix reset of HPDET after race with removal Charles Keepax
2013-11-14 16:18 ` [PATCH v3 3/7] extcon: arizona: Fix race with microphone detection and removal Charles Keepax
2013-11-14 16:18 ` [PATCH v3 4/7] extcon: arizona: No need to switch back down HPDET ranges Charles Keepax
2013-11-14 16:18 ` [PATCH v3 5/7] extcon: arizona: Add support for headphone detection on wm5110 rev D Charles Keepax
2013-11-14 16:18 ` [PATCH v3 6/7] extcon: arizona: Factor out different headphone detection IPs Charles Keepax
2013-11-15 0:58 ` Chanwoo Choi
2013-11-14 16:18 ` [PATCH v3 7/7] extcon: arizona: Improve headphone detection error handling Charles Keepax
2013-11-15 0:54 ` Chanwoo Choi [this message]
2013-11-15 1:03 ` [PATCH v3 1/7] extcon: arizona: Add defines for microphone detection levels Chanwoo Choi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=528570A9.1070109@samsung.com \
--to=cw00.choi@samsung.com \
--cc=ckeepax@opensource.wolfsonmicro.com \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=patches@opensource.wolfsonmicro.com \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox