Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp873357pxb; Fri, 22 Apr 2022 13:08:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT9nbvZKlJ2xdlD6CQu/lQeaTSagHVGNWEmPTHPdempo3Uu/CvCaeh+2qx3nqUl6Jnt1c1 X-Received: by 2002:a63:d347:0:b0:39c:d7d5:77fc with SMTP id u7-20020a63d347000000b0039cd7d577fcmr5286749pgi.201.1650658123465; Fri, 22 Apr 2022 13:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650658123; cv=none; d=google.com; s=arc-20160816; b=W7AUTae5P8JO1a1euGrt89xntUOSIyugMoXVvqbUt4KQV02tFwIZNjyIERd5Vbsjw9 /bxjCLi0Nxf8tFpGsHnKFDcXjY/ZiIaQbQRiOUy199SQU/0m2sHCUK7lvVecNZeEGNJM FGDdBYbjpeNzkhfE6B8UNBz/f0Wqq/nKWlwnpRuxz5cEcAZf9kgpGsoCQUjpV+OfCXvC njC/BZr0NVP2rZYzB6T5pn4SKsz+/WD9shfcxuux7aAzUbYMvmeZK3ijSWT9R2dX3tVS oIDvAMNxy6cmpANKuTWrbiEyE/rVueZzCW9Sg15qoL7r6gEoDAU74GEkcaErBJaAwqRV RqGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:reply-to:cc :from:dkim-signature:date; bh=hc/FXLJWiP6UGpg6+XjwuIc21v+5e2UZD50XsUxhbxM=; b=hwPAQJDVjtN/YA9NyG93DTPK+9Wn5JN3uJeRXqAk+H7d9ODNhc1/1Mv04/uIj7+nkl uMfQrFYwic31G/hzT4/6V0s2WoUFMW4M5L7h81TuIKOkwXDWSEKko+Po5wtb9n2LOAkC bhHPi6TkQZ8UunNSHvNBUiiT5Sp3k5fTueTXGNucZ7ZRe24ybc62I5tQpe54OYnHngYz FS6drfH5aqt6fdpWtg16XUrpwhjvn9N2afsHO52ZXDTbx0v50r9AnbJway1k1cngDjzs ekSBewcoUs52KxIGLmSlqEUslVGoVdwRCOmgeaImHLEC1yPXsyA01Lc8EtsP3D9fjVRh tiXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=wWl5N6f2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n190-20020a6227c7000000b005057a0d266asi7647243pfn.212.2022.04.22.13.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:08:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=wWl5N6f2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0FE9C24C13D; Fri, 22 Apr 2022 12:05:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379768AbiDTOyU (ORCPT + 99 others); Wed, 20 Apr 2022 10:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379716AbiDTOyS (ORCPT ); Wed, 20 Apr 2022 10:54:18 -0400 X-Greylist: delayed 61059 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 20 Apr 2022 07:51:32 PDT Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D94C1ADAA for ; Wed, 20 Apr 2022 07:51:31 -0700 (PDT) Date: Wed, 20 Apr 2022 14:51:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wujek.eu; s=protonmail2; t=1650466289; bh=hc/FXLJWiP6UGpg6+XjwuIc21v+5e2UZD50XsUxhbxM=; h=Date:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=wWl5N6f2jf0Cyy1AB6VJcv/EHm25vPsDZkJvYdCkVKq8Sqr7lqRfmKBrLvG+KFCJy 4oH6JpCEbvKR6jLE1DsTlxljfGjJ/joqicB6ZjYktsm4Lp1jn4p0jk9rxocgyw8mdJ A8bbZvisAICVm0kM7HBg3R6FlGIkif0gFjvYfq5vUgma8UMxdr/WvIz7PrIt1KjW4M x8SIyf7LN3RRHvysyHv0OG1+/u52YTdRfGem01Rh0tCRTkcmS3YtlOcDXAwwqCMoKK bqYS9VSgQmYzvu6rwmg/bnlSUIGhwSq7aRHBMgYun+U0vXWBWOLnoYsqt05JqrRzGp q+PXONr82v88g== From: Adam Wujek Cc: Adam Wujek , Guenter Roeck , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Adam Wujek Subject: [v3 PATCH] hwmon: (pmbus) disable PEC if not enabled Message-ID: <20220420145059.431061-1-dev_public@wujek.eu> In-Reply-To: <3da420df-234e-4701-2182-1f043b9ccc56@roeck-us.net> References: <20220419205228.303952-1-dev_public@wujek.eu> <20220420125421.415716-1-dev_public@wujek.eu> <3da420df-234e-4701-2182-1f043b9ccc56@roeck-us.net> Feedback-ID: 23425257:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Explicitly disable PEC when the client does not support it. The problematic scenario is the following. A device with enabled PEC support is up and running and a kernel driver is loaded. Then the driver is unloaded (or device unbound), the HW device is reconfigured externally (e.g. by i2cset) to advertise itself as not supporting PEC. Without a new code, at the second load of the driver (or bind) the "flags" variable is not updated to avoid PEC usage. As a consequence the further communication with the device is done with the PEC enabled, which is wrong and may fail. The implementation first disable the I2C_CLIENT_PEC flag, then the old code enable it if needed. Signed-off-by: Adam Wujek --- Notes: Changes in v2: - Rebase to the latest kernel - Update commit message Changes in v3: - Rework the patch, disable the flag first, then enable if needed. Adding three else statements to disable the flag will make the code less readable. - Update commit message drivers/hwmon/pmbus/pmbus_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index b2618b1d529e..d93574d6a1fb 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2326,6 +2326,9 @@ static int pmbus_init_common(struct i2c_client *clien= t, struct pmbus_data *data, =09=09data->has_status_word =3D true; =09} +=09/* Make sure PEC is disabled, will be enabled later if needed */ +=09client->flags &=3D ~I2C_CLIENT_PEC; + =09/* Enable PEC if the controller and bus supports it */ =09if (!(data->flags & PMBUS_NO_CAPABILITY)) { =09=09ret =3D i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY); -- 2.25.1