Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4786097rwd; Tue, 23 May 2023 12:29:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4UCE2+ctOah08niftsWqMB8abWKzEiTaRFWwg3UlCwCjEYRXNNUioF8548iVcnQXRYVfvu X-Received: by 2002:a17:903:248:b0:1a9:3b64:3747 with SMTP id j8-20020a170903024800b001a93b643747mr18748450plh.17.1684870191873; Tue, 23 May 2023 12:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684870191; cv=none; d=google.com; s=arc-20160816; b=wnSTccIWPNE9tRtAPUZ7KDl83JZiwHmk5rrA30i713k3Wg8h7PpdSdJs0lDIGv8E+Z i+1o7EnjwAn4AR86+UpGMa7QM9nigUno9m0GCS+9xt87ZclhXZk2Wn9u4a6jWEJKEZ8z xHbXk9UyQocpaQI4/0Qp9+zuuRrcaXRulyF0oHZ1w2Y7zVEDSOC4Y19C+ydXcQM/q2zo IHv7Ue2HVWiOJ1Ys2UuBd22fdGiaMAF1gVoGeTk5NfopeeQAkvJ6I1xm9KZ7l4z5IIKF 3FLpZyPl44n1Xpq52pvR1RGu8R4cjDyVtFSusdBFDXN8haeV6poLflVL4yPehwvQK4b1 YURA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=GwpnqVR8aNvgpuRkY6VY6JwLMYADSL1/IkauoF/LxZs=; b=vD0gLs+Q0x6q/Do15cixJQ253LdNNtnAyzZuq6OV4m60jFQ2RTEd4d3QHR1BD/8tnD nvtSNlrYDgLsvCo99TbboQ9lotJM4ibJgkcc+1NMSmlkSqFOjT2a55IYNUB/cD42hye7 /NHB45Viq2WUwkhMsNLQZlzg3GE4k5GpQgetTgFhnga1hCck9nGIwOBieVavUNNwyU08 tSXOFozWo5ey2Taa1cfidNtMyJgnfG/T4L38hvRNDUCh/XhhI6XOw+HUIs3XlOZOt0hE A9Q1wl6AWyoxHkNJXzLRqYBwAxxuy+P6MJMqCKvvxZ+sPMEe49UKH+DDsWTcDo+yspjA 5nvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HsU4mJiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d187-20020a6336c4000000b005348954e07asi1424173pga.1.2023.05.23.12.29.39; Tue, 23 May 2023 12:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HsU4mJiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238222AbjEWTHx (ORCPT + 99 others); Tue, 23 May 2023 15:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232417AbjEWTHw (ORCPT ); Tue, 23 May 2023 15:07:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 560C8119; Tue, 23 May 2023 12:07:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1407601D7; Tue, 23 May 2023 19:07:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 737D4C433EF; Tue, 23 May 2023 19:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684868868; bh=UjoI8KoEuWKKny/a0/2Y5UC4GhbSgwmY9f8yoNGDBVE=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=HsU4mJiq0+kQivmSwVpMkf5uxpXXhoM+pBA1jUMtHg5go78AmqSu7l72l92zJRXpv RJDDMwBOfFz/CMHXXIo7nw/p0IR76yzwBSAQHGT+YpvEYdq5kR6jiFQdNlP3aY6fWG fS7oB7GkQF8kmMaALLK7SQVAlHbOYD4SZPNVZxrMIXLMFWSxVz7EibcX9xCtyERUtD VRHWI0/3US9byvmSj06WSC17q7A7FutLewiIrWw/99uoSyvNf+fclRo2Ot8VD0qtjo QjuRcKLW2Fy4Kd66uIecU9w9pGA/kNL4iLARhPA+Cq4f/Jwwl6E4ThioYaT0FOqoMR w42g9stpb0+dA== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 23 May 2023 22:07:43 +0300 Message-Id: Cc: , , , , , , , , , , , Subject: Re: [PATCH 2/2] tpm, tpm_tis: reuse code in disable_interrupts() From: "Jarkko Sakkinen" To: "Lino Sanfilippo" , , X-Mailer: aerc 0.14.0 References: <20230522143105.8617-1-LinoSanfilippo@gmx.de> <20230522143105.8617-2-LinoSanfilippo@gmx.de> In-Reply-To: <20230522143105.8617-2-LinoSanfilippo@gmx.de> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon May 22, 2023 at 5:31 PM EEST, Lino Sanfilippo wrote: > From: Lino Sanfilippo > > Avoid code redundancy by shifting part of the code in disable_interrupts(= ) > into a subfunction and reusing this function in tpm_tis_handle_irq_storm(= ). > Make sure that in the subfunction the INT_ENABLE register is written with= a > claimed locality even if the caller did not claim it before. > > In the shifted code get rid of the variable "rc" by initializing the > interrupt mask to zero at variable declaration. > > Signed-off-by: Lino Sanfilippo > --- > drivers/char/tpm/tpm_tis_core.c | 36 ++++++++++++++++----------------- > 1 file changed, 17 insertions(+), 19 deletions(-) > > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_c= ore.c > index 458ebf8c2f16..8f4f2cb5520f 100644 > --- a/drivers/char/tpm/tpm_tis_core.c > +++ b/drivers/char/tpm/tpm_tis_core.c > @@ -468,25 +468,32 @@ static int tpm_tis_send_data(struct tpm_chip *chip,= const u8 *buf, size_t len) > return rc; > } > =20 > +static void __tpm_tis_disable_interrupts(struct tpm_chip *chip) > +{ > + struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); > + u32 intmask =3D 0; > + > + tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); > + intmask &=3D ~TPM_GLOBAL_INT_ENABLE; > + > + tpm_tis_request_locality(chip, 0); > + tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); > + tpm_tis_relinquish_locality(chip, 0); > + > + chip->flags &=3D ~TPM_CHIP_FLAG_IRQ; > +} > + > static void disable_interrupts(struct tpm_chip *chip) > { > struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); > - u32 intmask; > - int rc; > =20 > if (priv->irq =3D=3D 0) > return; > =20 > - rc =3D tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); > - if (rc < 0) > - intmask =3D 0; > - > - intmask &=3D ~TPM_GLOBAL_INT_ENABLE; > - rc =3D tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); > + __tpm_tis_disable_interrupts(chip); > =20 > devm_free_irq(chip->dev.parent, priv->irq, chip); > priv->irq =3D 0; > - chip->flags &=3D ~TPM_CHIP_FLAG_IRQ; > } > =20 > /* > @@ -755,20 +762,11 @@ static bool tpm_tis_req_canceled(struct tpm_chip *c= hip, u8 status) > static void tpm_tis_handle_irq_storm(struct tpm_chip *chip) > { > struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); > - int intmask =3D 0; > =20 > dev_err(&chip->dev, HW_ERR > "TPM interrupt storm detected, polling instead\n"); > =20 > - tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); > - > - intmask &=3D ~TPM_GLOBAL_INT_ENABLE; > - > - tpm_tis_request_locality(chip, 0); > - tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); > - tpm_tis_relinquish_locality(chip, 0); > - > - chip->flags &=3D ~TPM_CHIP_FLAG_IRQ; > + __tpm_tis_disable_interrupts(chip); > =20 > /* > * We must not call devm_free_irq() from within the interrupt handler, > --=20 > 2.40.1 NAK as invidual change w/o further discussion. Would need to be seen in context. This does not change kernel for better. If you want to wrap, please do it in 1/2 and then we can evaluate whether it makes sense or not. BR, Jarkko