Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4390672ybi; Mon, 27 May 2019 17:34:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzetVWpJwHZjPLaV68YIfg2vtw1II66MQXUrEdJlvCUXq0/UeHTlf5NWS56ByVZMrMi6TE X-Received: by 2002:a65:420a:: with SMTP id c10mr61232942pgq.376.1559003699697; Mon, 27 May 2019 17:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559003699; cv=none; d=google.com; s=arc-20160816; b=lt0n6EL8E0g/8plTTVxzM5XRPW3Y3nCDPCEFtG0te+EUk0mJGgHsj6s4+jWC+Wivxq i3jicSHxtgYmru7VcmE2aAu4QUFEEHlAAFrFXpzQEQTc799UkMw/GplBBJ0b74Ll2kgE Rd3EfjKvSS3K5b8J6nYbcM9d81rlPiNujXlb4R1IzwhR2YdSmJIfBu1GDC6Ie62P5B8Q hYQ/vVmumMizqQQtcAgd/TXjaVJlnz3m15cyocak5oGFcBkaee5VzVjqwKyQWpCAnA4W QCeFeQU/k5k6QPqdyvMf3Ebcivc5E4JhExaL5T4u3F+kfv7BJJTFJRZ0aVX1XWxKpfTY r3Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=IBU2i2x60PXCQpHcmTZUjF60sIqtVaUQ2A7Q1HpQhSY=; b=iNxx4U/CYJs1a+E4HTbnn+2Jz9GcYGyl2cMpcBhgk6crjSzcOmIlay0IFTbKk/A5y8 IHikXyHovtFGG/x8S6dyB+8eGaV8eoNyE4Yn3LBFcFifb2FxasRweiV3kP/rsUt7//sq BwlLsCOdw6Q5S+Nd2a5UXSQh2FDcIxOq4Eo042y1IgJyunfB8nAKguwIKs9flmAKgWxc /2x7OZeeBn5yxVoAMhylT0uUk2u+DLUD3phK0D2kQeIKh+IbZvjBzLaXQEyZWx0tSQ+J YNY5X5R8ve/De8sBN/JCQnF1QkQ+gYZnzqIKnQe2WRj4Xua8vJphSpZRkn+ZiNoWlZ8L JWbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Dof0bP7+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 199si10345249pfb.252.2019.05.27.17.34.42; Mon, 27 May 2019 17:34:59 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Dof0bP7+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727555AbfE1Ad0 (ORCPT + 99 others); Mon, 27 May 2019 20:33:26 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46070 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbfE1Ad0 (ORCPT ); Mon, 27 May 2019 20:33:26 -0400 Received: by mail-pg1-f193.google.com with SMTP id w34so5170135pga.12 for ; Mon, 27 May 2019 17:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=IBU2i2x60PXCQpHcmTZUjF60sIqtVaUQ2A7Q1HpQhSY=; b=Dof0bP7+5ryIVKEYrxrpraI1+1JHvC7NpZ2CoFuXZHktp4iSeTCvZ6w7KZc/COsC0M fxPhzW5Zhui/TA0PBDV1y3n5QBPpkH6yUlkEj6gcTd4oBHO06jZO0eSsQp2wy1b4eyRo x0mmbzo9OxGInvNWQa3RTl8zc/jjsSGhQipHO1kmMNUjen46Jt1ee8Ch16XjgEtJ+gVd QCfqmtTispz3Lm+88GOlNtrXdIOe9iiaDG7f+J74bzDgHK3cOA8AqZAHPNudEq9ZP4p9 apXuH1mPp03YNqLERKs+t3O2k9acFJmVSnf5bF1v1UfRhXKh4CCKlwSpWzVhwD2dIM6u XjaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=IBU2i2x60PXCQpHcmTZUjF60sIqtVaUQ2A7Q1HpQhSY=; b=p6zA1essdoQCs8xS0hwpu1kdlYUWZ/qTe+zcHqo3BSH3Li5IRIDJah1OejtNMzxuM5 N7a15IiyycSHEboliK29kd9jNgYmlGg8EZmMRwOyidmbmNhHm4umbN9EUcLIwvMQCody JGHCCYvnYVBDLMdK01o/156c9t6/50xE4niVS6aQ9KEhkMA3jwqfLy5c2TyPRVz9POqH qOKqlwnMaKujHOChI86aNFBaodd8G94ATrccShlxuML1xFclgbj0a29yftoARB3PXjbw cscGl/leYRK8gnMhZk2bRfd1+Do9Q7kTj+BCF4qZkm6XYr6qF3SVyAEY2LZKCXRxzNJw Rilg== X-Gm-Message-State: APjAAAUpsRbiSleDKw5URvDhQIbAdCfywIOD/wNA5u+TyHhVdypmzoRq TuEdDAG2C+xig1+L7LPibdo= X-Received: by 2002:a17:90a:e38b:: with SMTP id b11mr1796894pjz.117.1559003605642; Mon, 27 May 2019 17:33:25 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id v6sm6997029pfi.112.2019.05.27.17.33.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 17:33:25 -0700 (PDT) Date: Tue, 28 May 2019 08:32:57 +0800 From: Gen Zhang To: gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [Question: devm_kfree] When should devm_kfree() be used? Message-ID: <20190528003257.GA12065@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org devm_kmalloc() is used to allocate memory for a driver dev. Comments above the definition and doc (https://www.kernel.org/doc/Documentation/driver-model/devres.txt) all imply that allocated the memory is automatically freed on driver attach, no matter allocation fail or not. However, I examined the code, and there are many sites that devm_kfree() is used to free devm_kmalloc(). e.g. hisi_sas_debugfs_init() in drivers/scsi/hisi_sas/hisi_sas_main.c. So I am totally confused about this issue. Can anybody give me some guidance? When should we use devm_kfree()? Thanks