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 X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5F33C10F04 for ; Tue, 19 Jan 2021 14:33:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A60FE20715 for ; Tue, 19 Jan 2021 14:33:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405522AbhASOcz (ORCPT ); Tue, 19 Jan 2021 09:32:55 -0500 Received: from mail-oi1-f179.google.com ([209.85.167.179]:43398 "EHLO mail-oi1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404399AbhASNUn (ORCPT ); Tue, 19 Jan 2021 08:20:43 -0500 Received: by mail-oi1-f179.google.com with SMTP id q25so21077411oij.10; Tue, 19 Jan 2021 05:19:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kUDdGSpowK1CEbj8McVC+bBtkLq63WQr+Zql2YLqG5U=; b=APR2QqebwLBhixWfzvKPO1J2toMMxc5wGp2eyDUTVTgDdeiNhXK9t6GdizLJ1xkZqO 9FUJcPELlC8JsKvZHgBtP/Ouyr8wWl7/QC6N2kqS0Li/vWGRmut2IRxVbXPhlkaNolc+ YXtBkshomBq06Z92/3M3YA3v32X5IuS3Fjcs2T+j7H8yNeRu/EH+gKLfKCGJPh9Buv2w PH0oMcgsVw9Y6E7Bp34L49D7RMsDRVlVulxSNBXLwVyuZf1n6mqf1hlwIDnkodjDxUv5 TSBMz7CAVNaWyjyCpMwPiJ6OEpyBpr+lxLlu9AucA+mGHM9ffrkAt1B/xb2zhDj9eT2T EnZg== X-Gm-Message-State: AOAM5320PfM7sBJ4mg7+Ikxwfq1IGR98LK0HQaVUFF7cmGuDrycn1e5q +seTqS7UdaDCLlahsDcTmZN/4kOlHfyFAY4r+II= X-Google-Smtp-Source: ABdhPJx6gcAwtwXRqp5/IJOsji1kIJ+Z/62NGRk7TKZOMu+nRuZ+LcTh4icQ0/TaVor6jnR3+WE/obLzf1Lcm6Gy7n8= X-Received: by 2002:aca:5c05:: with SMTP id q5mr2555018oib.157.1611062368209; Tue, 19 Jan 2021 05:19:28 -0800 (PST) MIME-Version: 1.0 References: <20210118003428.568892-1-djrscally@gmail.com> <20210118003428.568892-5-djrscally@gmail.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 19 Jan 2021 14:19:16 +0100 Message-ID: Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name() To: Laurent Pinchart , Daniel Scally Cc: Linux Kernel Mailing List , ACPI Devel Maling List , linux-gpio@vger.kernel.org, linux-i2c , Platform Driver , "open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" , "Rafael J. Wysocki" , Len Brown , andy@kernel.org, Mika Westerberg , Linus Walleij , Bartosz Golaszewski , Wolfram Sang , Lee Jones , Hans de Goede , Mark Gross , Robert Moore , Erik Kaneda , Sakari Ailus , Andy Shevchenko , Kieran Bingham Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Mon, Jan 18, 2021 at 9:55 PM Laurent Pinchart wrote: > > Hi Daniel, > > Thank you for the patch. > > On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote: > > We want to refer to an i2c device by name before it has been > > s/i2c device/acpi i2c device/ ? > > > created by the kernel; add a function that constructs the name > > from the acpi device instead. > > > > Signed-off-by: Daniel Scally > > --- > > Changes in v2: > > > > - Stopped using devm_kasprintf() > > > > drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++ > > include/linux/i2c.h | 5 +++++ > > 2 files changed, 21 insertions(+) > > > > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > > index 37c510d9347a..98c3ba9a2350 100644 > > --- a/drivers/i2c/i2c-core-acpi.c > > +++ b/drivers/i2c/i2c-core-acpi.c > > @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, > > } > > EXPORT_SYMBOL_GPL(i2c_acpi_new_device); > > > > +/** > > + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI > > + * @adev: ACPI device to construct the name for > > + * > > + * Constructs the name of an i2c device matching the format used by > > + * i2c_dev_set_name() to allow users to refer to an i2c device by name even > > + * before they have been instantiated. > > + * > > + * The caller is responsible for freeing the returned pointer. > > + */ > > +char *i2c_acpi_dev_name(struct acpi_device *adev) > > +{ > > + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev)); > > There's a real danger of a memory leak, as the function name sounds very > similar to dev_name() or acpi_dev_name() and those don't allocate > memory. I'm not sure what a better name would be, but given that this > function is only used in patch 6/7 and not in the I2C subsystem itself, > I wonder if we should inline this kasprintf() call in the caller and > drop this patch. IMO if this is a one-off usage, it's better to open-code it.