From patchwork Thu Apr 15 09:38:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12204867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2BD9C433ED for ; Thu, 15 Apr 2021 09:41:06 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DF1B6117A for ; Thu, 15 Apr 2021 09:41:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DF1B6117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=+bQbrx2yhxcKN9QxxQSRWFX3yCe+eu1Gx1H/TKbH8qY=; b=EA5Vfx2WksaEqSv6may9oBP+bn kdey1f92wrzoQsZMAEnJk+/bq1sn6gt7r6jtSWdqzGdFadLkRpwnbrhGXwqCqJym1PNdYuvy2UyqE E1tIx4F8gJ2mKR+BzyWEd4YauAU0VG+Y/5LToJSwSFP6aQPnXZE8wV9Zm9TURYvAgKZ/nPjmnzCcK QjWvREkH6Hht9S/NnURqh8FeMPAzg1TcJTxoxm7P6POYm9r4T0W9pguFvMxt5Q0myfEudbZZykeit oiDOxmXaexSnXKivYdWEXFynhfxtapEPUfJBwBOafMylGmpMfqKNQcXapJSxOrqjX0lqoKW6MAzj3 l0LC+sOw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWySs-00FZMy-BA; Thu, 15 Apr 2021 09:39:10 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWyS3-00FYzE-Ir for linux-arm-kernel@desiato.infradead.org; Thu, 15 Apr 2021 09:38:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=l7z2ouZqcZvLyEOcdE7FnfhcpFO/282ITnfmb7UR/10=; b=jMcCoC7SWHpnqT8p9/Gw4Z7bfg 1d9yyTNDdy+uQ/wK7+sZmbomsUOXUxPqhymhH9KBXdVeoqdVUX+BIPlbDXj0GOsNY3XB76UbCdfIj nY8RVVw9Awj7I69i3yQj963AKxheUYXigEYYsqfZdoQ3shdGu9v5Xq3l5x8WlfUj3GgEr14nuUTIG vj9HOJ+gHDl/rz6djkDSM4YoJEoUllreOlHMcN01xXXZtmHDmuZO+pKkyV5Nr3fzT/1ydHy/xCtEh 04PmGKKNLJDcGcZqQTVTUjNSE4mtczOnSssCMFy9ins2uIlZnq/sM/jvM0hLFChp1KrKuo8EktJ1J wRpwn5uQ==; Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWyS0-008QvD-Uc for linux-arm-kernel@lists.infradead.org; Thu, 15 Apr 2021 09:38:18 +0000 Received: from mail-ed1-f72.google.com ([209.85.208.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lWyRy-0005z9-3g for linux-arm-kernel@lists.infradead.org; Thu, 15 Apr 2021 09:38:14 +0000 Received: by mail-ed1-f72.google.com with SMTP id f9-20020a50fe090000b02903839889635cso2910918edt.14 for ; Thu, 15 Apr 2021 02:38:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l7z2ouZqcZvLyEOcdE7FnfhcpFO/282ITnfmb7UR/10=; b=lAaBnr4st/aBpDYbmYDFyEPL5qBTtK0vZvzFixgXl5kKKM/Ruub0sdPFvfNKorKnRI o91w1tnTjey5mmbMwnKoxkTMnFVzMCoHbWwFn7MgjgzP2BNpTgy1o2LkVJFs6epF0TpR V4cUx5A7pVTYRJv09PT5V1f6sQdMixvWKQtygkR83bYH7fZvvkdC/ZBucgQ+2PT7SSeN 8Q4v81usLgTWhvduWO9gnRlG0SGhlGCKNbcaZ7IoTATJS4jkbr+twcvbJEf4qOneXyKd ntzT5G0vrERk9axB+nZbaktCpkm7P3pFB4ENsm2H2Sg6jlb95ZMJo6GJ5iVsF3AHZPP6 EYfg== X-Gm-Message-State: AOAM533/IHMFcizzxCK4zrSpp/xiB6CFheUx5aEf6JH/YmgVUtIndAN7 1tW8F14VpV5lQkfmyIOK+l9L6Sxcv4Xyml09RKxf95q+FaBHecdkzZ1HUiUhYQe6ISUW0iATg7J 38uh7Zy9uMey+CiikUtbqNnkrKIf1VwQ/VHmVJGuE8IqDtK1hFo4/ X-Received: by 2002:a05:6402:441:: with SMTP id p1mr3050358edw.298.1618479493846; Thu, 15 Apr 2021 02:38:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjTWhXTydv5lD8MaRLQ1f9/d9f9dV/fzvHNm6rGHF/jEEPA7jl/HaK9McUQpiTlM0C77cbrw== X-Received: by 2002:a05:6402:441:: with SMTP id p1mr3050341edw.298.1618479493689; Thu, 15 Apr 2021 02:38:13 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-192-147.adslplus.ch. [188.155.192.147]) by smtp.gmail.com with ESMTPSA id cq26sm1954088edb.60.2021.04.15.02.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 02:38:13 -0700 (PDT) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Alim Akhtar , Andrzej Hajda Subject: [PATCH 1/2] i2c: s3c2410: simplify getting of_device_id match data Date: Thu, 15 Apr 2021 11:38:02 +0200 Message-Id: <20210415093803.162673-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210415_023817_132926_0B1A4531 X-CRM114-Status: GOOD ( 12.18 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use of_device_get_match_data() to make the code slightly smaller. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Sylwester Nawrocki --- drivers/i2c/busses/i2c-s3c2410.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 62a903fbe912..ab928613afba 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -156,12 +157,8 @@ MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); */ static inline kernel_ulong_t s3c24xx_get_device_quirks(struct platform_device *pdev) { - if (pdev->dev.of_node) { - const struct of_device_id *match; - - match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node); - return (kernel_ulong_t)match->data; - } + if (pdev->dev.of_node) + return (kernel_ulong_t)of_device_get_match_data(&pdev->dev); return platform_get_device_id(pdev)->driver_data; } From patchwork Thu Apr 15 09:38:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12204865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A4AC433B4 for ; Thu, 15 Apr 2021 09:40:51 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9AF4660FD8 for ; Thu, 15 Apr 2021 09:40:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AF4660FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=olwTiLIDeww97NSXljXh1VqFbBhy5BXlUM5YmI+/fjM=; b=Tup9mqGTqHwObXScbOOGxfrQu uFO920VfycF1kIuOw7GIak6VCApyapCrLCrLY66aKjXfgZhomKh8EVReSND2S1e5jO/vBKwWbj2ii SSfsJAdR2SovqTTf2XjDrHFp+D+ta9z8OlgYKHpwCUB3V1o6mjMdePZVICwwoSOqZtSk1umpMlefj 26qXY6ngFs32ykpgFviMYRUMBfnQpwnkOqwN8Oh2qFr6rNzlVZsMZDAuZKta7XwrLZr1V/FtMkW4N mfeFvFWpqrdCHs98H1qh6oNXicwiS8v1MSNjOAh3Q44cfQyRcxLi6F/+UBz5LjzhXfn6GOGPX+jhN IDFnPoeAg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWySe-00FZJ3-J4; Thu, 15 Apr 2021 09:38:56 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWyS3-00FYzF-N9 for linux-arm-kernel@desiato.infradead.org; Thu, 15 Apr 2021 09:38:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=4aRJNj2Va0WuSj7bZqa+mg+YnYSMlodN/I41H1ztfK0=; b=pgvqYe/sh+nNV/LobvAjwDSM0G UYH17x/XJ2C29NpIYAuOYzZJQ8FXxSd0mKzOPejG5xLD67WpFlgtCwuuHzieiuZRDwcQ744ShydEy ci/JXsUxaK+Lkhp6m8/o9o7QeBp50m077xmsTt7ckB/XZZt79GmSk1vcK86R0OuWWTRnwWHdPERru jvo6EyTmC9YMnOC1YW1u9TWaqp/iB0Y0PqJHGLD//+oJSZyKqHargy2Tti4SZaPfJNgT109vuE8H4 8zUwAO67LIJ1W4YXmpjD8kyR8+ZE2yfA72nSzvSrSz/cNI1B4HuUqGVIQdLGx+yunN1B0FqcGM/HJ imoht2Iw==; Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWyS0-008QvE-Ud for linux-arm-kernel@lists.infradead.org; Thu, 15 Apr 2021 09:38:18 +0000 Received: from mail-ej1-f70.google.com ([209.85.218.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lWyRz-00060C-Hv for linux-arm-kernel@lists.infradead.org; Thu, 15 Apr 2021 09:38:15 +0000 Received: by mail-ej1-f70.google.com with SMTP id d11-20020a170906370bb029037c87968c04so727059ejc.17 for ; Thu, 15 Apr 2021 02:38:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4aRJNj2Va0WuSj7bZqa+mg+YnYSMlodN/I41H1ztfK0=; b=KBDAqwLQETMlMH9gxYFSMT3jC1Y1cEvMdwba8S9NVnSjHhZxEN59QY+aqYg5nDCdoh jxfPrTXlZkgj6oeQBUif1nqcy1KYiJAFGPO143v2LAO+4qnHQjLnE4HQkgQjXpd7XMuv H/RxPIXajfnToS1vkEP8EuI2QUxjPb6vxcV54O8w04Z5mWkMChuliPeJKNYbKlSIzPsb lDNTnKuMzCFuRRcasnnOgXi1o7C2Bc4ukWysegap9yE+swWB/z5kWfQdONNTTlFORKQn uu8WVLBTFlk4hbu84r6elZebVp0d8B/6fbYCv9M+kkTHXkzxAxuDdr9OgdwN9k+Zx99B 6vtg== X-Gm-Message-State: AOAM531MsHPu6k8+UjHLhqzmWm1AItL9sSxOQTAbTF2/yA3Trv/2vU0t 53R7469TKqvZUv68wczBXmBSxBYlQ0KuIoepvX3uRNyGDlYEwxIcxfDxxyc3xnlza1osAI10AJQ I7HbwguLFo4KrgZGIQ+D5Rxr5l8dy3Xp30e4b4GG2jNcNAUAShEl2 X-Received: by 2002:a05:6402:12c3:: with SMTP id k3mr3104008edx.86.1618479494841; Thu, 15 Apr 2021 02:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8hCXucMNCy2MFa0IAxrCmDHgzWOO5+IZIekrpsC964e9WmaUDMs8NNfahxQW97g1nkmD62A== X-Received: by 2002:a05:6402:12c3:: with SMTP id k3mr3103999edx.86.1618479494737; Thu, 15 Apr 2021 02:38:14 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-192-147.adslplus.ch. [188.155.192.147]) by smtp.gmail.com with ESMTPSA id cq26sm1954088edb.60.2021.04.15.02.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 02:38:14 -0700 (PDT) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Alim Akhtar , Andrzej Hajda Subject: [RFT 2/2] i2c: s3c2410: fix possible NULL pointer deref on read message after write Date: Thu, 15 Apr 2021 11:38:03 +0200 Message-Id: <20210415093803.162673-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210415093803.162673-1-krzysztof.kozlowski@canonical.com> References: <20210415093803.162673-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210415_023817_137089_B9EEC2B5 X-CRM114-Status: GOOD ( 16.44 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Interrupt handler processes multiple message write requests one after another, till the driver message queue is drained. However if driver encounters a read message without preceding START, it stops the I2C transfer as it is an invalid condition for the controller. At least the comment describes a requirement "the controller forces us to send a new START when we change direction". This stop results in clearing the message queue (i2c->msg = NULL). The code however immediately jumped back to label "retry_write" which dereferenced the "i2c->msg" making it a possible NULL pointer dereference. The Coverity analysis: 1. Condition !is_msgend(i2c), taking false branch. if (!is_msgend(i2c)) { 2. Condition !is_lastmsg(i2c), taking true branch. } else if (!is_lastmsg(i2c)) { 3. Condition i2c->msg->flags & 1, taking true branch. if (i2c->msg->flags & I2C_M_RD) { 4. write_zero_model: Passing i2c to s3c24xx_i2c_stop, which sets i2c->msg to NULL. s3c24xx_i2c_stop(i2c, -EINVAL); 5. Jumping to label retry_write. goto retry_write; All previous calls to s3c24xx_i2c_stop() in this interrupt service routine are followed by jumping to end of function (acknowledging the interrupt and returning). This seems a reasonable choice also here since message buffer was entirely emptied. Addresses-Coverity: Explicit null dereferenced Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Krzysztof Kozlowski --- drivers/i2c/busses/i2c-s3c2410.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index ab928613afba..4d82761e1585 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -480,7 +480,10 @@ static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) * forces us to send a new START * when we change direction */ + dev_dbg(i2c->dev, + "missing START before write->read\n"); s3c24xx_i2c_stop(i2c, -EINVAL); + break; } goto retry_write;