Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1969500pxb; Fri, 29 Jan 2021 09:33:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlvzXDqPzbv5+5c+NKO/WAda+LV12X77pRFqSv9Mh+fnkpH8c9q4fAAnTlWc71gYfzaU7A X-Received: by 2002:a17:906:6449:: with SMTP id l9mr6019510ejn.320.1611941632519; Fri, 29 Jan 2021 09:33:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611941632; cv=none; d=google.com; s=arc-20160816; b=AtJppzVRWSR7j48uCU+H7rz/0rdD5gjA8ny2fcU+BxYVeigLoD1enjcb5UmuklAxym dBoC0m19/eWdNxIIyKJ2eeI46qEO+vkzXQpR90/4nJaV7ZMto8cfJUq5M6nr4Tq5Wtef 2nHy0zmNiecwp2/y+a+wkzoGC0cucxJIDZmg2+Wz5IYOilyOeF2aUBtpDpvnzrsE8vbf yarNO9He0OTLAfZzRCkF4FoBxU3VAQ0ZXxhyEyhgZCHnPSDvGf9J15hVtnbPw+IUYCLs LRJ+Tuk03DEcbDSclpKoWSA0DWCpvJeyj482JsmcUFbGXHAyb5VAcDvcNDTxprKbjL1P 0gPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=HA0gkxeHl86DkS/BFcIDueC3TPGHfYXzdAIAmf73Bt8=; b=xGYYoHp2jVcinQe5Ghw8XSHtFv+oVpPNtT9jcu0xdOk5wm5a3Ob7CkZED+exT8DI6i aDuYbbfO0wDegw/xOW1pUnqWJy8K0RlbgI0OxOy6ZEBKo8dZSju8ZMCtQgaNVL9V8Xk3 zK2IXX7WV/IQVXgUT8zJ6dMLGs8dNFl3Rlk1z+4eaGfMPvpTy2RAK2Zx7wX4n2fYqA3r wU3aHt53f3ncR1YLYLwOFHZrFJAfq0oeQwV0/nIl4ibr5RlkQkGzHC+KR9r1aMblSUDg d9xi1+5wJrk6MYjTidtsuA4BF9+vOqXM0xBH9OYw5AIA0MWQ/brc801YTNtMHhgjrbZF oh1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ce1iSdTH; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si5152257ejb.622.2021.01.29.09.33.27; Fri, 29 Jan 2021 09:33:52 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ce1iSdTH; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232561AbhA2Rbn (ORCPT + 99 others); Fri, 29 Jan 2021 12:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232579AbhA2R2t (ORCPT ); Fri, 29 Jan 2021 12:28:49 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDCC2C0617AB; Fri, 29 Jan 2021 09:26:37 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id s15so5579645plr.9; Fri, 29 Jan 2021 09:26:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HA0gkxeHl86DkS/BFcIDueC3TPGHfYXzdAIAmf73Bt8=; b=Ce1iSdTHwgOtweIGJKZegnVu5wTWONPwek4Y2DIQUDoGF/uC4f7Ff8wCeleDGo8GZr 1uFYzyYQh1hzQoz8hGqsGYZOedU98/mRIjz1Uy0dmvPuBKH0okoaQCRfw8D73nizbLit 40QKm/f6JhxaAWkSoEI1vgKkSaAB3vs2sdeVm+8xjUzBd7cHLpzPu5A9zc/EXspraozq d5MQbkEF+3PkChkfIAOc1mm5D6wD94a0P2UvD/j0AJt3yoQ0DnYBGZzLsfycCqMMcxk4 NZz80cLeaNlkldeNZ6Xj7O1Y+VE9XvHzx2eD6j7Ot7ZKEtIDVDKwnluFOa2H8xh1FJ7m M0Zg== 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=HA0gkxeHl86DkS/BFcIDueC3TPGHfYXzdAIAmf73Bt8=; b=cfAt51+GvSbLaL6JO9FfN44gAhWTfTeZt+jKa7NSB/+YnDk4J9Cxx7tglEILM7Eo3a 0tlNj5QKTydaUuIQH/HyFxnKBkmqGvgNeIyMv7iOFZKRxSWK6ppYpfy/inPgl/40kLWx 5MiJXJF1/QuTNwh+HNrRIVbKrSnYdJlvZ6Dpx8mCJiuqNntWN4Jz2+PHQfckaNv6qzO3 Pl/2gLkWt/46KU1F0ECHxNeB2fUE3dLqH9IugXxX/39gQGUg5dk1U+ShVOj/KHagVHIE Nu+t/IRVFdCopKkhseyDWPJPq0tY9Ph8UH2x/BVrO4uBu6H5UGmfJnviYuowddRWG1MP heWA== X-Gm-Message-State: AOAM531pf9zQTerS4KXXjDmDmatDYU1ZfV7GGkd+MQh9yDHtApgMs5Aq AZN0k5KgMBIaGU0GClGnlN2u9SuUtJ7+DH5POpc= X-Received: by 2002:a17:902:758b:b029:df:d1f6:9af9 with SMTP id j11-20020a170902758bb02900dfd1f69af9mr5276324pll.21.1611941197275; Fri, 29 Jan 2021 09:26:37 -0800 (PST) MIME-Version: 1.0 References: <20210129081917.1808218-1-quanyang.wang@windriver.com> In-Reply-To: <20210129081917.1808218-1-quanyang.wang@windriver.com> From: Andy Shevchenko Date: Fri, 29 Jan 2021 19:26:21 +0200 Message-ID: Subject: Re: [PATCH] gpiolib: free device name on error path to fix kmemleak To: quanyang.wang@windriver.com Cc: Linus Walleij , Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 2:01 PM wrote: > > From: Quanyang Wang > > In gpiochip_add_data_with_key, we should check the return value of > dev_set_name to ensure that device name is allocated successfully > and then add a label on the error path to free device name to fix > kmemleak as below: Thanks for the report. Unfortunately... > + ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); > + if (ret) > + goto err_free_ida; ... > +err_free_dev_name: > + kfree(dev_name(&gdev->dev)); ...this approach seems to create a possible double free if I'm not mistaken. The idea is that device name should be cleaned in kobject ->release() callback when device is put. Can you elaborate? -- With Best Regards, Andy Shevchenko