Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2453821imu; Mon, 17 Dec 2018 02:09:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/VaJ3mMU/s39FC9iWnNnAJVQvG7/NsNwS4CNR5kI9oCMFtjFmbjSoq5v+B/cZNPsc42KSaL X-Received: by 2002:a63:2263:: with SMTP id t35mr11660282pgm.69.1545041352361; Mon, 17 Dec 2018 02:09:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545041352; cv=none; d=google.com; s=arc-20160816; b=bykbY/Ke6j93MmuGWItrPpQBRouMyZJPaNJV/phR3SmwUFnKzaRpfBfrZjXHKb+0U/ RzJQHCRtj1hdxV9GuNn53WZMAWUdkM/mjxCf2TDyeycfpDjJEgu242r4b3hK6ELToGC9 LdAV69mia0JGxpycgmgWb40qGWscziQEy9TlxfvpD3/l8vEt6Zkjz7kqSzlp41GRlA8q vqcWZ4jOTAUoAJBarr0up3FqwYbi0o23kTBvHnJRqn9kkV2SSpMxtAbO4ZL/mxA3EAk9 HzExUPulnw/P2Qq2kaDyT/7Vw7H3MDmjbKHPxA9nTzIrGRCz8Fkcg04MGw93TUarghAx 0a1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from:dkim-signature:dkim-filter; bh=9REB8f30WGRuS0Tcl1g6Pqrfjh6KRQ6kdeVVt5jKBBU=; b=kiI4Ypo/dA8Edp1mGHta3sbp88thzTq6RwxOqRPa8oNN082uil4lZExXeaD2E8GTpP L1R7NhW1WkxNZb4TdXZ/T+fA8CQoDpAMFquwaEWXd+YOZKP6O0gTAzuBGJyQpwmuIfz2 lBvZUTTrQW9sfUiVrAGOuOv7nMTgQPlMK86NvRszRJCLOTkOnIDVvdusOfBiK3i/VqQ+ bK6WljqXhTuSOhs+wCXFcmOUTlSeyyVhtJE1Lkaguqh2zZC9PRhI0kLsm8SGlYlBSWih Ufsfy2Jx2Tobc2Bu3jbB8KXqBLgAljs3J6gxHCaZ/wAK1PXbrcsunMK0350drd+TxuGh 628w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@piap.pl header.s=mail header.b=InK8bBXt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=piap.pl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8si10798043pgn.325.2018.12.17.02.08.56; Mon, 17 Dec 2018 02:09:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@piap.pl header.s=mail header.b=InK8bBXt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=piap.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731589AbeLQJMU (ORCPT + 99 others); Mon, 17 Dec 2018 04:12:20 -0500 Received: from ni.piap.pl ([195.187.100.4]:43180 "EHLO ni.piap.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbeLQJMU (ORCPT ); Mon, 17 Dec 2018 04:12:20 -0500 Received: from t19.piap.pl (OSB1819.piap.pl [10.0.9.19]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ni.piap.pl (Postfix) with ESMTPSA id 6F371441E45; Mon, 17 Dec 2018 10:12:14 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 ni.piap.pl 6F371441E45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=piap.pl; s=mail; t=1545037935; bh=9REB8f30WGRuS0Tcl1g6Pqrfjh6KRQ6kdeVVt5jKBBU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=InK8bBXtAyGN0is62NNooyS8c9LvJvK/7yj/t7jVlxBLDLad1ivUaLjcLI6hnEwyl icA38aJ5QjRIp3NP7aUOByxV0vIznyP2Uiacca0riUd/O3Ak/YNoFXE/vmIc2jgGt3 1ozK/4OXm7DEzkAiKawsEL4qdcGV7gsl0o06Whbc= From: khalasa@piap.pl (Krzysztof =?utf-8?Q?Ha=C5=82asa?=) To: Fabio Estevam Cc: linux-kernel , "moderated list\:ARM\/FREESCALE IMX \/ MXC ARM ARCHITECTURE" , linux-i2c , Lucas Stach Subject: [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call(). References: Date: Mon, 17 Dec 2018 10:12:14 +0100 In-Reply-To: (Fabio Estevam's message of "Mon, 3 Dec 2018 09:21:32 -0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 132976 [Dec 17 2018] X-KLMS-AntiSpam-Version: 5.8.3.0 X-KLMS-AntiSpam-Envelope-From: khalasa@piap.pl X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Info: LuaCore: 227 227 6e72a1529a7b33ae962e5643d747d57d679cf0c7, {Tracking_DKIM, one}, {Tracking_ sender_matches_from}, {Tracking_text_let_digits}, Auth:dkim=pass header.d=piap.pl, DmarcAF: none X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, 2018/12/11 14:32:57 X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2018/12/17 00:28:00 #9249116 X-KLMS-AntiVirus-Status: Clean, skipped Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 90ad2cbe88c22d0215225ab9594eeead0eb24fde changed the i.MX I2C bus driver to use a notifier whenever the base clock ("ipg" - 66 MHz peripheral clock) rate changes. Unfortunately one can't use the container_of() macro this way - the first argument has to point to a member of the bigger struct (last argument). Merely pointing to the same value isn't enough (the clk variable which has its address passed to the macro is the clk in notifier_block, not the one in imx_i2c_struct, even though both pointers point to the same clk struct). This bug causes kernel panic when the IPG clock rate changes (e.g. if any clock derived from IPG changes). Signed-off-by: Krzysztof Halasa --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -510,9 +510,9 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb, unsigned long action, void *data) { struct clk_notifier_data *ndata = data; - struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk, + struct imx_i2c_struct *i2c_imx = container_of(nb, struct imx_i2c_struct, - clk); + clk_change_nb); if (action & POST_RATE_CHANGE) i2c_imx_set_clk(i2c_imx, ndata->new_rate);