From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0245CCD54AF for ; Tue, 19 Sep 2023 10:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231948AbjISKuX (ORCPT ); Tue, 19 Sep 2023 06:50:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbjISKuF (ORCPT ); Tue, 19 Sep 2023 06:50:05 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 197AAE42; Tue, 19 Sep 2023 03:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695120573; x=1726656573; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=0klRbsvIFZBpR09ph8KYAGbk+boJM0fgzVGIgayXCZk=; b=QyP3/PEro9qghCyxel3147XZK80Y/MA9LeaTwxNvxEEVCD2wGXxgzGeO RpTwnG+rriyeHboQpQsr5d9g7Yq0AfMBM2ZApyWRn36c1gTDV8LCBdpJE zI7QMhQWuaT5wi36/185KQwbv07tZbjxx403LqWQjSQoork7AB8ICk+we CDFtljzqsw+I7Y2AjJ6efs/xupmEWNKzkU43cEg6xAoLfZAZHSxPfBmnS DRvUihBFE3+DSw22HfAwErk02Knnyvat06oDbWHm1F+kXUUcjUXvr+B/S t42EdJ8t6imLPODkQuoH7mX1w1geerw4N5eZp/FoOo27OYeviLJObMRV+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="377218220" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="377218220" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 03:49:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="1076939400" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="1076939400" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga005.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 03:49:29 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC0) (envelope-from ) id 1qiYII-0000000Ek42-3X8J; Tue, 19 Sep 2023 13:49:26 +0300 Date: Tue, 19 Sep 2023 13:49:26 +0300 From: Andy Shevchenko To: brgl@bgdev.pl Cc: Linus Walleij , Kent Gibson , Alexey Dobriyan , Peter Zijlstra , Linus Torvalds , akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v4] gpio: sim: fix an invalid __free() usage Message-ID: References: <20230918145533.14642-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 19, 2023 at 12:31:36AM -0700, brgl@bgdev.pl wrote: > On Mon, 18 Sep 2023 17:31:36 +0200, Andy Shevchenko > said: > > On Mon, Sep 18, 2023 at 04:55:33PM +0200, Bartosz Golaszewski wrote: ... > > Of course this can be replace with... > > > >> + line_names = kcalloc(line_names_size, sizeof(*line_names), > >> + GFP_KERNEL); > > > >> + if (!line_names) > > > > ZERO_OR_NULL_PTR() check here, but I assume we discourage use of it. > > Why? There are less than 40 instances of using it in the kernel. kmalloc() > returns NULL on failure. Nope, k*alloc*() returns ZERO or NULL on failure. That's what most developers are missing :-) > >> + return ERR_PTR(-ENOMEM); Hence either one needs to check for 0 the size given to the kmalloc(), _or_ to check for all possible return values from it. -- With Best Regards, Andy Shevchenko