Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp657550ybl; Thu, 23 Jan 2020 05:32:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzfW/U9sj6OfwVPHLDJPrwvuJ8C4YE33h0yii7f8AugZnYzZq3GhrEhP24L62TTKlV/UWaD X-Received: by 2002:aca:72d0:: with SMTP id p199mr10887338oic.40.1579786336693; Thu, 23 Jan 2020 05:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579786336; cv=none; d=google.com; s=arc-20160816; b=DVy8bnZ7I6x7v4IM4j32pTiHkbdOQ/fypOzO8xi0w4GKira2TKo7p4Tq3YD0ZGOQ09 2E1+Q7dXqrAkzBQENtMucem8pjrXSq/uh/UO6qwlYSaXz6pGkhzybEXHHWJQRma0rn+9 6EpcUgQ5cf8Td/UPsMBp9sRF9vrIPY9CngExSKqKc79Jm+vXSIHI1jFCu4v8UapaJ+rf nqUx5V3jmRbqXc8qLxNnKs/QQFA+apnZB0EkQprM0hun+LX7+znjn6rACaS2J4JoRb8s MJfcNg818SKRlao9EmOpRlEWMP7L/WTaqJnMCirGL3dUEV+VKIZ5o3zyxKZ0z/7wekpZ 15eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=0+L/2IhzPeQzIOBWlkZ5pb6nsfpL9PHovfEkpJKJ33U=; b=gfKWOWIAfwCvb2otNe9Cg6wEdjEXe6XRwuI52yRb+nOx0wju4NvNdNXynlA70HO3g1 lr0QbjmpZb7ptlnSllar6y7JeJJPvoISJpPPvu6URYF9zUdAiQqAULcfyF1dvxsO5agH 8EQNPvgeXYO/MV1PbmS03MrVPio7bc1vXUnP66SFh3er8yguQhCnEhL3ROHKl9bvZcmQ G/jN9TT5HW3wX304WVeX8uzuTVz914CkFox7SP5sRtuBlIke/jkGC6HFcvsMMlCt4ANn 7DCzGMZ3+7U/6n4xuT4NHb1RgY959MOTBJWfkd1G52xoiMOIQKNIpacG2p3rBE1lq8rm a0cw== ARC-Authentication-Results: i=1; mx.google.com; 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 t23si1132031otk.304.2020.01.23.05.32.04; Thu, 23 Jan 2020 05:32:16 -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; 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 S1726796AbgAWNa7 (ORCPT + 99 others); Thu, 23 Jan 2020 08:30:59 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:36741 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgAWNa6 (ORCPT ); Thu, 23 Jan 2020 08:30:58 -0500 Received: by mail-ua1-f66.google.com with SMTP id y3so1007358uae.3; Thu, 23 Jan 2020 05:30:57 -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=0+L/2IhzPeQzIOBWlkZ5pb6nsfpL9PHovfEkpJKJ33U=; b=tfZ8xdMXne2j6zAYSePkCxIvjgsESJ2alS2OrK1gvvUe9qj08TPmb2CWYRjOH4kDYk 5F9VtLFQ7thkAFH3CCL3vWBHT6A7gLnxA0Nbbja98kpXZr+kTkjdY76QpSo1MI4vCJZc uKzyYnbxDVbakiYl4bT9+fVvK1wh+o6vPDu7U0p/sFEbejl+OMXF8bHr4bcYPEj9PU4B AuHHjGqDLJf5mKDhzH3dY/2VE/BkQGWEojVeCXJkLXJ8Mvz3nksoipmWzSb3v1sjLZXD T7C93+Y4F41CKy8YfFiVBs8JXOPccmP6ApM+ZTPLR7kWtdbkoy3vL5TzWkU/KS5ql1RN 4iLw== X-Gm-Message-State: APjAAAUdT1rWfzN9PaDYU97tRW+uJFtX1HEJVnpdpPRqgvSEHxaZQGdA e3UAZX4vGa2w59BI7jnXipfFWX+AI3Gc2SgGzBe+j0UU X-Received: by 2002:a9d:7984:: with SMTP id h4mr11516407otm.297.1579785825019; Thu, 23 Jan 2020 05:23:45 -0800 (PST) MIME-Version: 1.0 References: <56c7b6d5-1248-15bd-8441-5d80557455b3@free.fr> <8f1f01a1-b0c7-77d5-7d01-dd53811fa217@free.fr> <91058d8f-7075-6baa-6131-cce1ccd160a6@free.fr> In-Reply-To: <91058d8f-7075-6baa-6131-cce1ccd160a6@free.fr> From: Geert Uytterhoeven Date: Thu, 23 Jan 2020 14:23:33 +0100 Message-ID: Subject: Re: [RFC PATCH v2] clk: Use a new helper in managed functions To: Marc Gonzalez Cc: Arnd Bergmann , Kuninori Morimoto , Stephen Boyd , Michael Turquette , Dmitry Torokhov , linux-clk , LKML , Russell King , Linux ARM , Bjorn Andersson , Robin Murphy , Sudip Mukherjee , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marc, On Thu, Jan 23, 2020 at 1:18 PM Marc Gonzalez wrote: > On 23/01/2020 11:32, Geert Uytterhoeven wrote: > > On Thu, Jan 23, 2020 at 11:13 AM Marc Gonzalez wrote: > >> A limitation of devm_add_action is that it stores the void *data argument "as is". > >> Users cannot pass the address of a struct on the stack. devm_add() addresses that > >> specific use-case, while being a minimal wrapper around devres_alloc + devres_add. > >> (devm_add_action adds an extra level of indirection.) > > > > I didn't mean the advantage of devm_add() over devm_add_action(), > > but the advantage of dr_release_t, which has a device pointer. > > I'm confused... > > void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); > int devm_add_action(struct device *dev, void (*action)(void *), void *data); > > devres_alloc() expects a dr_release_t argument; devm_add() is a thin wrapper > around devres_alloc(); ergo devm_add() expects that dr_release_t argument. OK. > devm_add_action() is a "heavier" wrapper around devres_alloc() which defines > a "private" release function which calls a user-defined "action". > (i.e. the extra level of indirection I mentioned above.) > > I don't understand the question about the advantage of dr_release_t. OK. So devm_add_action() is the odd man out there. > >>>> + void *data = devres_alloc(func, size, GFP_KERNEL); > >>>> + > >>>> + if (data) { > >>>> + memcpy(data, arg, size); > >>>> + devres_add(dev, data); > >>>> + } else > >>>> + func(dev, arg); > >>>> + > >>>> + return data; > >>> > >>> Why return data or NULL, instead of 0 or -Efoo, like devm_add_action()? > >> > >> My intent is to make devm_add a minimal wrapper (it even started out as > >> a macro). As such, I just transparently pass the result of devres_alloc. > >> > >> Do you see an advantage in processing the result? > > > > There are actually two questions to consider here: > > 1. Is there a use case for returning the data pointer? > > I.e. will the caller ever use it? > > 2. Can there be another failure mode than out-of-memory? > > Changing from NULL to ERR_PTR() later means that all callers > > need to be updated. > > I think I see your point. You're saying it's not good to kick the can down > the road, because callers won't know what to do with the pointer. Exactly. > Actually, I'm in the same boat as these users. I looked at > devres_alloc -> devres_alloc_node -> alloc_dr -> kmalloc_node_track_caller -> __do_kmalloc > > Basically, the result is NULL when something went wrong, but the actual > error condition is not propagated. It could be: > 1) check_add_overflow() finds an overflow > 2) size > KMALLOC_MAX_CACHE_SIZE > 3) kmalloc_slab() or kasan_kmalloc() fail > 4) different errors on the CONFIG_NUMA path > > Basically, if lower-level functions don't propagate errors, it's not > easy for a wrapper to do something sensible... ENOMEM looks reasonable > for kmalloc-related failures. Indeed. If devm_add() would return an error code, callers could just check for error, and propagate the error code, without a need for hardcoding -ENOMEM. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds