Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1404183pxb; Sun, 11 Apr 2021 18:49:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKy+65OUj/TrTuJXpP6KKU6lfqvYwjvxuTafkD2LtcUAgQCgbg0iVmhVi33/rUQYVwedcJ X-Received: by 2002:a05:6a00:b54:b029:207:2a04:7b05 with SMTP id p20-20020a056a000b54b02902072a047b05mr22650154pfo.12.1618192170704; Sun, 11 Apr 2021 18:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618192170; cv=none; d=google.com; s=arc-20160816; b=wIPEAJCUc+dJTD/VbTzkgerQWYJEVQTWIlomQa4kfMk2PRkpZTKRt7pJ0te0lTRvPk i1ld1PDNToFIgUDiQ+mT/S/pEP8quhgRssB95quCjxZ7rP9UBAxebhNPDE21mMdrCfn5 new2yzQhqC6Sd6Np4n0x1lm1YloC5biBJIixUxyn/omEqVuPAHQoY2UlS8ewXmZUoQBM zbHmCHovEYwGRFYsOsvYVhdKAzNDIRap5IBiLDZA5DUlC6DwRUdPurAwR8kbPkL6lGcy wd61A9OCtAC/BNjMQzfT75mzbCcYZSg2FLouB6M6vRiBQ3iKDN6A0k2rv5B3eYQuQoic +wCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=i6swzHPSrm0qV1N2yohtfar3D7FFS6VDGJ3N8DG92fY=; b=ej55520ItoVJj/QkpeXuCGEwACLH1sj8AFX5hf0xHXBwwNUgqMbs62olMhLk6d+EP3 HvRhtj1/JamZxl6kK+AVsIDneifuLH7CtDbmLp9VqrxlqouBpF/kuq85D00QpXOl1Mq0 f/0exQWgdKaOU51sWFFg3A41tAjVqlxt2zUE5KuUNdUSyo88hKeRq/VnuV8mhZf7mkq3 HZ6ozFX+dobfmORuI1itOjQRBaQt2YHP3bMMglxroiPK3AC9GgZOXkkYedGTOv/HD8LF Vb9MFylazN9p4CPkHBmYOYS5sO/3Se6WUuh7S574qKV92NQ3phO8hoGM5Iy7ywroTojq MD6g== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s5si11577715pgi.376.2021.04.11.18.49.17; Sun, 11 Apr 2021 18:49:30 -0700 (PDT) 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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236366AbhDLBPG (ORCPT + 99 others); Sun, 11 Apr 2021 21:15:06 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17308 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236248AbhDLBPF (ORCPT ); Sun, 11 Apr 2021 21:15:05 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FJW1V4y3Zz9ygF; Mon, 12 Apr 2021 09:12:30 +0800 (CST) Received: from [127.0.0.1] (10.40.188.144) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Mon, 12 Apr 2021 09:14:37 +0800 Subject: Re: [PATCH] staging: fieldbus: simplify devm_anybuss_host_common_probe To: Sven Van Asbroeck , Tian Tao CC: Greg KH , , Linux Kernel Mailing List References: <1617957240-53633-1-git-send-email-tiantao6@hisilicon.com> From: "tiantao (H)" Message-ID: <44f55f42-cb52-f705-c40a-6d5c1844f56b@huawei.com> Date: Mon, 12 Apr 2021 09:14:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.40.188.144] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/4/9 19:58, Sven Van Asbroeck 写道: > Hello Tian, thank you for the contribution. See below. > > On Fri, Apr 9, 2021 at 4:33 AM Tian Tao wrote: >> Use devm_add_action_or_reset() instead of devres_alloc() and >> devres_add(), which works the same. This will simplify the >> code. There is no functional changes. >> >> Signed-off-by: Tian Tao >> --- >> drivers/staging/fieldbus/anybuss/host.c | 20 ++++++++------------ >> 1 file changed, 8 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/staging/fieldbus/anybuss/host.c b/drivers/staging/fieldbus/anybuss/host.c >> index 549cb7d5..2924e68 100644 >> --- a/drivers/staging/fieldbus/anybuss/host.c >> +++ b/drivers/staging/fieldbus/anybuss/host.c >> @@ -1406,7 +1406,7 @@ void anybuss_host_common_remove(struct anybuss_host *host) >> } >> EXPORT_SYMBOL_GPL(anybuss_host_common_remove); >> >> -static void host_release(struct device *dev, void *res) >> +static void host_release(void *res) >> { >> struct anybuss_host **dr = res; > You're expecting a double pointer as the argument here... What about doing it like this? diff --git a/drivers/staging/fieldbus/anybuss/host.c b/drivers/staging/fieldbus/anybuss/host.c index 549cb7d5..c97df91 100644 --- a/drivers/staging/fieldbus/anybuss/host.c +++ b/drivers/staging/fieldbus/anybuss/host.c @@ -1406,32 +1406,26 @@ void anybuss_host_common_remove(struct anybuss_host *host)  }  EXPORT_SYMBOL_GPL(anybuss_host_common_remove); -static void host_release(struct device *dev, void *res) +static void host_release(void *res)  { -       struct anybuss_host **dr = res; - -       anybuss_host_common_remove(*dr); +       anybuss_host_common_remove(res);  }  struct anybuss_host * __must_check  devm_anybuss_host_common_probe(struct device *dev,                                const struct anybuss_ops *ops)  { -       struct anybuss_host **dr;         struct anybuss_host *host; - -       dr = devres_alloc(host_release, sizeof(struct anybuss_host *), -                         GFP_KERNEL); -       if (!dr) -               return ERR_PTR(-ENOMEM); +       int ret;         host = anybuss_host_common_probe(dev, ops); -       if (IS_ERR(host)) { -               devres_free(dr); +       if (IS_ERR(host))                 return host; -       } -       *dr = host; -       devres_add(dev, dr); + +       ret = devm_add_action_or_reset(dev, host_release, host); +       if (ret) +               return ERR_PTR(ret); +         return host;  } > >> @@ -1417,21 +1417,17 @@ struct anybuss_host * __must_check >> devm_anybuss_host_common_probe(struct device *dev, >> const struct anybuss_ops *ops) >> { >> - struct anybuss_host **dr; >> struct anybuss_host *host; >> - >> - dr = devres_alloc(host_release, sizeof(struct anybuss_host *), >> - GFP_KERNEL); >> - if (!dr) >> - return ERR_PTR(-ENOMEM); >> + int ret; >> >> host = anybuss_host_common_probe(dev, ops); >> - if (IS_ERR(host)) { >> - devres_free(dr); >> + if (IS_ERR(host)) >> return host; >> - } >> - *dr = host; >> - devres_add(dev, dr); >> + >> + ret = devm_add_action_or_reset(dev, host_release, host); > ... yet you pass in a single pointer here. Is that going to work? > >> + if (ret) >> + return ERR_PTR(ret); >> + >> return host; >> } >> EXPORT_SYMBOL_GPL(devm_anybuss_host_common_probe); >> -- >> 2.7.4 >> > . >