From patchwork Tue Apr 12 06:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaoqian Lin X-Patchwork-Id: 12810157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23A96C433F5 for ; Tue, 12 Apr 2022 06:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iQPAJzjvCSCdRsIgvXLfXGM8UDLXJoGVqTxbSXHuqu8=; b=zaSqur06KKRJkz T+TF/EKG9z//1wDvt8K2LkYfg9+8ViVPem5KPgWEABEQCSbdupKhQ5IZ0+JMBQAIemwBDrGZz0Lt3 SzlJ5yT3i0FCkb3c29mOH6HKLQ0eTRwpRP+dtg5OAj9apBhJUmTFx38ASN1PA3ShOJLAl8FBOP2nq 2nfb6Cr97aKMY8FW72aBdk7d4xrOQQ2da4mf9UmYZStgHjGRNxmMa+5G3xk5PAH4Z9oUDVH1NbvWK Ly/+nQ0neDEzhjN4Sqa2rslS5apNb/fVdi34NEEUfSLVf8QPMIa/4o9mCOVJ0mxhY6pCGQFkhpbxe q2u3wq0awxnPReGUc0gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neANe-00Byqt-16; Tue, 12 Apr 2022 06:52:02 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1neANb-00Byp7-0R for linux-arm-kernel@lists.infradead.org; Tue, 12 Apr 2022 06:52:00 +0000 Received: by mail-pg1-x52b.google.com with SMTP id k14so16392837pga.0 for ; Mon, 11 Apr 2022 23:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references; bh=RBbYU01e+AFbhWY3ZuGeFMRIuU/CVxN8Q/n9EQ09lHU=; b=a8AKCKRLwEJ+ICpyl0Ua49RR5GoUvlGs65zLny8zLr9rq8FPqaowjaciyPlu0e0Ra5 K38C9SACTeDtneV0qgjKDJBJUEWchIR3VIhC9SpjB3IXVvUnsnuVOkKl9UFn60wHF9N4 JMw0aiBOyEdWx9p+NYgkcgqLhB7jNVb8eS1V2+vluyREM6O2fqdKfAdlLOt1xz7uWDTN dws3dSdt0MyP5UQhVa68Spk7WNjnYcPTgH+KtTzNkjZwyCBJHqy2nDP9oqdP1YDoavPZ MA6Qx75v3pkISAyQJgVWK+UJjDfbAk4jHEqdT5BM1mpcOuzxHlGUkGZ32J3dlFvJxCxN SZcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RBbYU01e+AFbhWY3ZuGeFMRIuU/CVxN8Q/n9EQ09lHU=; b=x8o4OXwMNR95r6sTFGvTwPkq9QZi1xhQFqgFhHk+6Qp1d/v6TFuccelODCnduufMjn LdLkKIXe2B1J5DntoYUYF0MmK8VMsfPZqJyG9eXE832n7XfxPiIkZarD5BstbGPSu71h fTEqS8SH90cSw3yGtgv2FPpf8thtdMywjRiNsMUKruGJxzpevk3q7NFl+5npQn/dFkfD +H2hef8ZwYVHd15xjISuMrdV9mCaGFFZq8K6zLtoZj5DrbqkKvld/m+PZi6qTxYZZOc9 +3f/bXTa1Ty2OKuztrRPiofoKXfQBYptrO2WAnu9dceGBrkiNDFnT9zlmghNV/PtpLGC Lj2w== X-Gm-Message-State: AOAM530I4opbzSLJFEIYfmTUu7dZHcTYO2r2reTGndAHWVHhkSTeep09 6hILOaclwMq8J93/8qiAvOw= X-Google-Smtp-Source: ABdhPJxPK9vIH5rkg+Zivi5zxRj7BATlOjv/oQFrgbrSqTgZiffo9i573UyyUxob/kW5MlB279CmGA== X-Received: by 2002:a05:6a00:1488:b0:4fa:ac61:8b11 with SMTP id v8-20020a056a00148800b004faac618b11mr37315301pfu.58.1649746315502; Mon, 11 Apr 2022 23:51:55 -0700 (PDT) Received: from localhost.localdomain ([159.226.95.43]) by smtp.googlemail.com with ESMTPSA id ng17-20020a17090b1a9100b001c9f79927bfsm1654577pjb.25.2022.04.11.23.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 23:51:55 -0700 (PDT) From: Miaoqian Lin To: Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue , Miaoqian Lin , Kees Cook , Philippe Schenker , linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] iio: adc: stmpe-adc: Fix wait_for_completion_timeout return value check Date: Tue, 12 Apr 2022 06:51:45 +0000 Message-Id: <20220412065150.14486-1-linmq006@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220411_235159_105217_2C298500 X-CRM114-Status: GOOD ( 14.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case Fixes: e813dde6f833 ("iio: stmpe-adc: Use wait_for_completion_timeout") Signed-off-by: Miaoqian Lin Reviewed-by: Philippe Schenker --- changes in v2: - Fix same issue in stmpe_read_temp. --- changes in v3: - update the patch subject. --- drivers/iio/adc/stmpe-adc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c index d2d405388499..83e0ac4467ca 100644 --- a/drivers/iio/adc/stmpe-adc.c +++ b/drivers/iio/adc/stmpe-adc.c @@ -61,7 +61,7 @@ struct stmpe_adc { static int stmpe_read_voltage(struct stmpe_adc *info, struct iio_chan_spec const *chan, int *val) { - long ret; + unsigned long ret; mutex_lock(&info->lock); @@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info, ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); - if (ret <= 0) { + if (ret == 0) { stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, STMPE_ADC_CH(info->channel)); mutex_unlock(&info->lock); @@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info, static int stmpe_read_temp(struct stmpe_adc *info, struct iio_chan_spec const *chan, int *val) { - long ret; + unsigned long ret; mutex_lock(&info->lock); @@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc *info, ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); - if (ret <= 0) { + if (ret == 0) { mutex_unlock(&info->lock); return -ETIMEDOUT; }