Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4819620ybl; Wed, 22 Jan 2020 05:22:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyyPiB6YSmvgTjq4TDwm4BaIxXPcYXMm95kyBXOI0xs2b4x39k3c8jmxoCy9uhxq1rjkmd9 X-Received: by 2002:aca:1309:: with SMTP id e9mr6700489oii.7.1579699322289; Wed, 22 Jan 2020 05:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699322; cv=none; d=google.com; s=arc-20160816; b=AHmlrl184XbVjHf0rx1R6Z8v34rBvVrpfftPJgnrGjbMj4xc/RQLLK9UpP5OYx6AZx ebXy6VkiYfEt+G090ZSa6xAIOhCBvRRS84lG+CYcY2hAh9YtWUIqof6OiDY1FEkrXiB6 btI++O+Ubp0vCaWkPvLoziouCcNvHNXsCEBy3bM5WcZCwjU3zVg/GdrZel0oSIKwUxdf ADadv0k1JWdgJD/8aWcXZqAIAiHiMnTxlM7KcbQJC9nnZU5c7OW0aF8Soal5rjoIy9rb ZQ6+Ksz3iWMF07P2QH/ijaPYWzqaM5cE8X5/HVpqTTm+z4OEw4H/tyAVcTDEscOkJUwO 0IgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NtCRRlmZnba+1CeAW5JgWZGgD4qRppo8bY4ri3+2f8U=; b=w2W2QP38JV0hvvLcPk47GIky5/12gGNFybfGRYIZrhHBEqlIz4Wj+Qnocc5qmePopf Qof3y6JcRDC+gvvhToalOZR0n3Hv5e8/IyKU2/+9HwEqZA/WmBa4uMZquy6CE1Ek6TTc rBYtP1enLCZpy5IosWXXL//MIcvTa5yO5FgOS72orN/JCI21Hnd+fUtd04rjbRdWzaU8 Diz/FjR9pGpnziVcNlkTWZ7CMsme4j0j8+1FlYIFyM7JbU6+fCM1eJx6bkADPVWHUUM0 eLwk51hWy7sS7lj+KsLd5XcbrOyNSiYJdCfL8Xerr34ub0BiTOIYlVbUchpXdEVyBzPs idng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2B1RZigh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si20138940oib.142.2020.01.22.05.21.50; Wed, 22 Jan 2020 05:22:02 -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=@kernel.org header.s=default header.b=2B1RZigh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729413AbgAVNUQ (ORCPT + 99 others); Wed, 22 Jan 2020 08:20:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:36366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729397AbgAVNUO (ORCPT ); Wed, 22 Jan 2020 08:20:14 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 73A9C2467E; Wed, 22 Jan 2020 13:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699214; bh=I+VLj7wPA/ByWO/czUC3hP/jbE0YMB6KcBdEWKzI7BY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2B1RZighAJQ7LRfj2C7mS2x68X4o2fjx0pGhuZZLwQR1lSVwv5xdTcECBRNSgEy6D +keH0oGO95yMo3uoQO2Z6izMcO/hhbct17VrHq/g3glp14XtXujKPDFkTKwP42pSEB grkus9GIMo41O9iQ9SjTnYZ/gl3JcfSAQvcd5FZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Stephan Gerhold , Jonathan Cameron Subject: [PATCH 5.4 039/222] iio: imu: st_lsm6dsx: Fix selection of ST_LSM6DS3_ID Date: Wed, 22 Jan 2020 10:27:05 +0100 Message-Id: <20200122092836.329332842@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephan Gerhold commit fb4fbc8904e786537e29329d791147389e1465a2 upstream. At the moment, attempting to probe a device with ST_LSM6DS3_ID (e.g. using the st,lsm6ds3 compatible) fails with: st_lsm6dsx_i2c 1-006b: unsupported whoami [69] ... even though 0x69 is the whoami listed for ST_LSM6DS3_ID. This happens because st_lsm6dsx_check_whoami() also attempts to match unspecified (zero-initialized) entries in the "id" array. ST_LSM6DS3_ID = 0 will therefore match any entry in st_lsm6dsx_sensor_settings (here: the first), because none of them actually have all 12 entries listed in the "id" array. Avoid this by additionally checking if "name" is set, which is only set for valid entries in the "id" array. Note: Although the problem was introduced earlier it did not surface until commit 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1") because ST_LSM6DS3_ID was the first entry in st_lsm6dsx_sensor_settings. Fixes: d068e4a0f921 ("iio: imu: st_lsm6dsx: add support to multiple devices with the same settings") Cc: # 5.4 Acked-by: Lorenzo Bianconi Signed-off-by: Stephan Gerhold Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -911,7 +911,8 @@ static int st_lsm6dsx_check_whoami(struc for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) { for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) { - if (id == st_lsm6dsx_sensor_settings[i].id[j].hw_id) + if (st_lsm6dsx_sensor_settings[i].id[j].name && + id == st_lsm6dsx_sensor_settings[i].id[j].hw_id) break; } if (j < ST_LSM6DSX_MAX_ID)