Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1026315pxa; Wed, 12 Aug 2020 21:07:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOSTIKfYXT6XGBOlw0E6YgRCxdGmGrpcuGsD1Tam318uIyHzgJuoxi5TxouNUlWlIwFypG X-Received: by 2002:a17:906:57cc:: with SMTP id u12mr3153151ejr.422.1597291636642; Wed, 12 Aug 2020 21:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597291636; cv=none; d=google.com; s=arc-20160816; b=FYIcwhc/Xr3RAHZjMa8z3L4LrOjtRoIjC6mUWwLRwgQ5meS7IslPqNmchbQn48DObN D7Y8Z2AvPzXmNcz3+Y5xKzVgZR1ahw0VDjkiNd70CrFGQ5m2YzSWBdN+BVdTz+tawRGe 3ZbFRn/lNbnWSyL6DNVaVPh6pNZrF9DBDkxPsod0G0t+R41tUmqydbkmKLdxEaRap0hp nFO+0I22fhbUsM0HBfyqfvROSlLl64s/jSKSNnXmJpVwtY7ZC3S2JNVGBQbn2MY5bHWl 4JV1CMKsTPRSuEJJiCmIn8aHuWmFAMAvm2EJK/N4izoA50NZozUl1NywQcbtZCDp43gd IQ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uFADKmKh7X3diP0daFq4Uh/PnuNyIFdsVOnr2X8DxEQ=; b=OnPQkdi7BwdiWUqW2CIgwi7IurQMbXWAQDhmSqSYFbsc5bkPuuFqT+x5dJ1hHuwJEG S0CYYhj6FNMt/vVi9TNBAf7gKELvNB74KgGQR9ps4ZcMdcolProgSK3GZwc124fNOK1E xQFLHkuEPla3ztK/Z3TbxJ0q1vU9lzBQm3o591ZqhGQuItLpl2oikfJxLeetTCU2wTcx tiML4ZrJ1aH0srlZFseIALK403rKb6wp6ZtTuBUVqEK3w4wv9ItToSV31YuJJo8ebcPh c6bD4lUQgDnn5e2K3IzB7GSVNFIwNbQiWs1RpxZLy2/c+IK9GAS7qQid3z7gN0pNejTo a+sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YZOkuBJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g23si2583877edv.507.2020.08.12.21.06.53; Wed, 12 Aug 2020 21:07:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YZOkuBJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725829AbgHMEGQ (ORCPT + 99 others); Thu, 13 Aug 2020 00:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgHMEGP (ORCPT ); Thu, 13 Aug 2020 00:06:15 -0400 Received: from mail-vs1-xe44.google.com (mail-vs1-xe44.google.com [IPv6:2607:f8b0:4864:20::e44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A57C061383 for ; Wed, 12 Aug 2020 21:06:15 -0700 (PDT) Received: by mail-vs1-xe44.google.com with SMTP id n4so2222366vsl.10 for ; Wed, 12 Aug 2020 21:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uFADKmKh7X3diP0daFq4Uh/PnuNyIFdsVOnr2X8DxEQ=; b=YZOkuBJsgTHvjSG9g5a/xPxSZTOJqLyRy5QvKnBhTb1LmpDhPoDH0G+SwUIP8hDuPC Kd6o2Vn2ksK+EGfYUQO1sKlBCj1lPLSED3wGvd6pb/aR0VOGkNhNHXM0bodOhZpy1LQH NehGXzZu+3AQNedbVRYBnAW25PW3VOvt+hfpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uFADKmKh7X3diP0daFq4Uh/PnuNyIFdsVOnr2X8DxEQ=; b=ipQ+gVgD2HgZpCNNfsWnebH4KBxZu64x+rynzkAFggQZvrnBzHI33FJ+xeXsVE1AXi YLNYC/WOPD5A8RBZm5D22/jZibjvmXW4HWOlyFW+QvJdjqTXqVqmt0inpbptZNKzs/HR DfQo/rYNRctZup3Sch9EFGKEgctcl4jwE71+fJxxIr5jj+Fr5uKkUD1QTScfsFHeYqIG BCVuJniKcvWDLRo/pvBkG61h6iQ2UxLL05kfurUhe5fsFLufl/Nixj0aCT+TPFi2Gl3K z3+3dRNfeaiKPb8iFPV1QLEgdZFcXezsAcsgeYNxudIgpCdrByraPrW94/Jg9KITuKgk QI5g== X-Gm-Message-State: AOAM530BqHIemrd5lUVqA5LXIORO53LLxbqDEru+q4YMQ2LWSwLc1vAS 8F6ChXZGcEidpT1tfei0nFN6eVUFmt80KQB9WYynUQ== X-Received: by 2002:a05:6102:85:: with SMTP id t5mr1848857vsp.1.1597291574574; Wed, 12 Aug 2020 21:06:14 -0700 (PDT) MIME-Version: 1.0 References: <20200811065902.2100551-1-ikjn@chromium.org> In-Reply-To: <20200811065902.2100551-1-ikjn@chromium.org> From: Nicolas Boichat Date: Thu, 13 Aug 2020 12:06:03 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] power: supply: sbs-battery: don't assume every i2c errors as battery disconnect To: Ikjoon Jang Cc: Sebastian Reichel , "open list:THERMAL" , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 2:59 PM Ikjoon Jang wrote: > > Current sbs-battery considers all smbus errors as diconnection events disconnection > when battery-detect pin isn't supplied, and restored to present state back > on any successful transaction were made. when any... is made > > This can leads lead > to unlimited state changes between present and !present > when one unsupported command was requested and other following commands > were successful, e.g. udev rules tries to read multiple properties. > > This patch checks battery presence by reading known good command to > check battery existence. > > Signed-off-by: Ikjoon Jang > --- > v2: fix return value checking of sbs_get_battery_presence_and_health() > --- > drivers/power/supply/sbs-battery.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c > index 6acb4ea25d2a..db964a470ebc 100644 > --- a/drivers/power/supply/sbs-battery.c > +++ b/drivers/power/supply/sbs-battery.c > @@ -878,10 +878,17 @@ static int sbs_get_property(struct power_supply *psy, > if (!chip->enable_detection) > goto done; > > - if (!chip->gpio_detect && > - chip->is_present != (ret >= 0)) { > - sbs_update_presence(chip, (ret >= 0)); > - power_supply_changed(chip->power_supply); > + if (!chip->gpio_detect && chip->is_present != (ret >=0)) { > + bool old_present = chip->is_present; > + union power_supply_propval val; > + > + sbs_get_battery_presence_and_health( > + client, POWER_SUPPLY_PROP_PRESENT, &val); > + > + sbs_update_presence(chip, val.intval); I don't think you can/should assume that val.intval will be set correctly if the return value is negative (even if that's what the functions currently do, it'd be too easy to accidentally change them). So I still think you need to have: ret = sbs_get_battery_presence_and_health... sbs_update_presence(chip, !ret && val.intval); > + > + if (old_present != chip->is_present) > + power_supply_changed(chip->power_supply); > } > > done: > @@ -1067,11 +1074,12 @@ static int sbs_probe(struct i2c_client *client) > * to the battery. > */ > if (!(force_load || chip->gpio_detect)) { > - rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); > - > - if (rc < 0) { > - dev_err(&client->dev, "%s: Failed to get device status\n", > - __func__); > + union power_supply_propval val; > + sbs_get_battery_presence_and_health( > + client, POWER_SUPPLY_PROP_PRESENT, &val); > + if (!val.intval) { > + dev_err(&client->dev, "Failed to get present status\n"); > + rc = -ENODEV; > goto exit_psupply; > } > } > -- > 2.28.0.236.gb10cc79966-goog >