Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2343106rdg; Mon, 16 Oct 2023 00:53:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdmOGoP1H7eXcHRZcCfUkUq++WWyZr99F7uZEv7L6pEmHJ+eR/kL86hLsfkhL42z4Wy17M X-Received: by 2002:a05:6e02:1104:b0:352:5fcb:1401 with SMTP id u4-20020a056e02110400b003525fcb1401mr28187786ilk.8.1697442830223; Mon, 16 Oct 2023 00:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697442830; cv=none; d=google.com; s=arc-20160816; b=QVD4ANfLPB8763g0vt21aA4NThNrYLXKBLtVK/UkxTztsCC23oitrKw9N+WExj1ZxR aSdOcqmU5HXP/M+hea9fDUY60XWdYgZFu4IFDQR3hQy6l20k7qi08TWagX95/7HnDgJN DkLjmh1M2NY2YI7vJx230F/wWMCMCNq1Lw5p1gGgD0i9GkLQueEMaF/9W3+Jbzpz8jIC 8SeblB+djQ0+ubrg0rj2OJScesqSut3ESZ63A9LPIEKmqRL7IKOzfMwQE6wMNVfviX8y rao3XS1SpNg93v6cUAeH1B7nVYsvGro/VLi9Z7PGF/bFAC1ERDsQ9UkMqtoOMnhgbNn4 Vh5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FDB3y7Ia/SB+vW/ccdoaV2UXaamR8f8Cm+B4tUr3ZSU=; fh=TeHa0Y+pQrULeDQt9ShTBO568GTj2oZ/bV2hyZWKYuU=; b=bboEObtEF7kakhrteBixIw20reYGLgDCaMkeLjlEk71CnQSFRpmAiUOdAOypO8hOwv SB8gWEEfZRnWK3LCFpsb4nVK9y0Pd6keRTD6X2nvioHv9RGvuf59xLa/FfBTBiwQqX2p otqoKhhNPymIBw3lQglMGPNiDww/+lCff6XFx76utNNjBhEwQC7k5DMc4e7sL8WqywPS wEjDcU/k9lwEwxZNJxiNbHIj5Ph15hhVjh9SF21DU/GUbjx8PwGHQTO2w2taIDHU1Cei GtHNTMmXsjFglZFQZ1HWfFm/iwMtE+jwVJHHmISO/Cu8SDd+27F6XyrUxZr6Mq38O3am pEVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UaQ3UF6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s80-20020a632c53000000b0057c7d7036b8si7050981pgs.389.2023.10.16.00.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:53:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UaQ3UF6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E967780AD8E2; Mon, 16 Oct 2023 00:53:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbjJPHxq (ORCPT + 99 others); Mon, 16 Oct 2023 03:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjJPHxp (ORCPT ); Mon, 16 Oct 2023 03:53:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF33AD; Mon, 16 Oct 2023 00:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697442823; x=1728978823; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ixX0RLZqUvYdCViWR3QC9hB3nJJiOPVVdf0NCyC6K4w=; b=UaQ3UF6tZkAdy8GjSn568XIgUttoPiobxb/anzT0RCEmhnGpl/YHT8Aq xSd3Ial+nQn7nN94iT0vDsYgwbOfS4GFnjEOPamMIwofmz9RaBrxmZHdF M0USy4cjdxp1z7qu6ky/elz3CG8KH9zNvgSfTNaSwLE8ruAlcfSsfzJUX AGrimZho/9pmqTaej9CLmiu8a0n+kaKx5nWq8HHI5TJHVqakgK0uXWujn VRHBLsEwD65ku0z2B4JtkiJ4irzXKFDta7gLOsCjwDFOXKlKhzB4WksuN xahhZpcydK8iSiBAnJfYgk8NE0gxp1W5IMlBq90eo6EbbrZQkY52zBIha A==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="370544795" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="370544795" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 00:53:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="929256670" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="929256670" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga005.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 00:53:41 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC2) (envelope-from ) id 1qsIPy-00000005x8u-2BI4; Mon, 16 Oct 2023 10:53:38 +0300 Date: Mon, 16 Oct 2023 10:53:38 +0300 From: Andy Shevchenko To: Angel Iglesias Cc: linux-iio@vger.kernel.org, Biju Das , linux-kernel@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Subject: Re: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices Message-ID: References: <9f8489d82325b2dfb5c8c71c3d558d509b2b01bf.1697381932.git.ang.iglesiasg@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9f8489d82325b2dfb5c8c71c3d558d509b2b01bf.1697381932.git.ang.iglesiasg@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 00:53:49 -0700 (PDT) On Sun, Oct 15, 2023 at 05:16:26PM +0200, Angel Iglesias wrote: > Improve device detection in certain chip families known to have various > chip ids. ... > +#include Probably you don't need this, see below. ... > ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); > if (ret < 0) > return ret; > + if (i == data->chip_info->num_chip_id) { > + size_t nbuf; > + char *buf; > + > + // 0x, so four chars per number plus one space + ENDL > + if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf)) > + return ret; First of all, it _implicitly_ returns 0 here... > + buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL); > + if (!buf) > + return ret; ...and here. Second, kmalloc_array() has that check inside. Third, define this magic 5 either as strlen(), or a constant (in latter case with the comment of its meaning). > + for (i = 0; i < data->chip_info->num_chip_id; i++) > + snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]); Fourth, use incremental position, i.e. use retuned value from snprintf(). > + dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id); > + kfree(buf); > + return ret; As per "first" and "second" above. > } -- With Best Regards, Andy Shevchenko