Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2076087pxb; Mon, 18 Jan 2021 07:39:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKMmgMwHtIpkiV/faGEZlSFekDSpgk1zhLaH+34ceskRjzGSYMy4S86EVVYP5yq8wD5a1x X-Received: by 2002:a17:906:3fc1:: with SMTP id k1mr222242ejj.58.1610984342159; Mon, 18 Jan 2021 07:39:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610984342; cv=none; d=google.com; s=arc-20160816; b=LonQAwMtDqhKDDfZ5fMjrnpPUN5yZCnIrRfzfz9K/QsHeaW1tfZ9TA0MKxM9WhqUx4 htjG0bkHfD7qlgbJaJG8uaOLqtv4oOaTFpWkrKw6d/3uX1h0Vl0olX41oOzvaco+vAmm 0IfMLgJdg6tVHhK7QTRrM6JxPVt4QaBE8BvqfoOeusNgnCN/brJiSuK1L1CU1LEFVhXC Lp3Z1Yjr1Dy7kD5t8USjk+Amdl7+W6MtYTo2tkirpSY/hiLkqE1jD0cY9xrCe0Kogcz7 aInYUMOqANL3dC5mibReB1aPrjP4zSrJVDfZTsG6jkOqUq4bC9LsdpXmTnTHEeQr1TlE aeOQ== 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 :ironport-sdr:ironport-sdr; bh=qeq/NeypxSj5zXUX0vThFJHI/K6WhnRw9A4ciB9zEwA=; b=OO9F9VydUawYk0RQVhq9KR91LpjF8Ht+lxdA6PcUGbgCUc2EG5X1MyTsbW09XaNWA7 KJcrWipFzHhzfUUV1sSGgG6PL5NJbVrNSycvuC33RD3YNHIfVkvFo7fkmRKVuMpGpXVM GYFGD0vgPuFfE+/hhnaK+ENVsX0c+zjpVEQOXNrPDUsRGYEXjIcwGCp0tyU8jXawIRk+ G3d5rSqctf8eB3bLxYyCOsSsNJMJFEuM65JlUJUtnDNVqq+0sez0NJsvKAac//mRGDyZ dcMC0HulRxAxWwM5hrc8Ibw48Xdvoai7xQoGivDT9BBY4zKr5KHZLdwWBZVKsfwjPK9E O29w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si2777883edx.449.2021.01.18.07.38.30; Mon, 18 Jan 2021 07:39:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406025AbhARPgE (ORCPT + 99 others); Mon, 18 Jan 2021 10:36:04 -0500 Received: from mga02.intel.com ([134.134.136.20]:63972 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405947AbhARPdG (ORCPT ); Mon, 18 Jan 2021 10:33:06 -0500 IronPort-SDR: qKLvXPzNERWBf1sJYJFKIoxPpHwWWhK2KqeG+GDfS5ma8jrjOK8jHdWbxyPHLu7Iui0cKRJW03 /v+0mxgX4/zQ== X-IronPort-AV: E=McAfee;i="6000,8403,9867"; a="165906259" X-IronPort-AV: E=Sophos;i="5.79,356,1602572400"; d="scan'208";a="165906259" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2021 07:31:20 -0800 IronPort-SDR: KN74coCIjSJQJohpAoATfBJRz1D5s39ayV45mr7VDhXTMgjcNrAmW2NhN0GSFFsKeMr8Pp3dRd kvs8VKtCwqwQ== X-IronPort-AV: E=Sophos;i="5.79,356,1602572400"; d="scan'208";a="466400206" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2021 07:31:15 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1l1WVu-002I8S-2f; Mon, 18 Jan 2021 17:32:18 +0200 Date: Mon, 18 Jan 2021 17:32:18 +0200 From: Andy Shevchenko To: "Rafael J. Wysocki" Cc: Hans de Goede , "Rafael J. Wysocki" , Linux ACPI , LKML Subject: Re: [PATCH v1 1/2] ACPI: scan: Rearrange memory allocation in acpi_device_add() Message-ID: <20210118153218.GX4077@smile.fi.intel.com> References: <3494203.VBaj39JGmp@kreacher> <2999734.9HhbEeWEHR@kreacher> <8218eff4-6629-ac20-ec3f-a66aad445bb6@redhat.com> 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 Mon, Jan 18, 2021 at 04:16:16PM +0100, Rafael J. Wysocki wrote: > On Sat, Jan 16, 2021 at 1:37 PM Hans de Goede wrote: > > On 1/14/21 7:46 PM, Rafael J. Wysocki wrote: ... > > When I have cases like this, where 2 mallocs are necessary I typically do it like this: > > > > const char *bus_id; > > > > ... > > > > } else { > > acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id), > > GFP_KERNEL); > > bus_id = kstrdup_const(acpi_device_hid(device), GFP_KERNEL); > > if (!acpi_device_bus_id || !bus_id) { > > kfree(acpi_device_bus_id); > > kfree(bus_id); Just to be sure, shouldn't it be kfree_const() ? > > result = -ENOMEM; > > goto err_unlock; > > } > > acpi_device_bus_id->bus_id = bus_id; > > list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); > > } > > > > ... > > > > So that there is only one if / 1 error-handling path for both mallocs. > > I personally find this a bit cleaner. -- With Best Regards, Andy Shevchenko