Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp82319ybe; Sun, 1 Sep 2019 20:57:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD2oX5rV2BhCOW6szbF6qACgGnYMNyLYVLjh+6GDEJ0o2ASbb2t+z/sasPn7SUqXXghJwJ X-Received: by 2002:a63:f401:: with SMTP id g1mr24394627pgi.314.1567396632187; Sun, 01 Sep 2019 20:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567396632; cv=none; d=google.com; s=arc-20160816; b=Xa1jlhpEVEQyWQ6k+sLF0YhLYjXQAUO+Ce2g0/QmHQD6+o6OYtOsDquTWSSSHHqJ+L LycHqHuHFfbyhfloCoFU/wCcSIOZB2jyAF8UN3dGqHZysDuN8rQnq3oe36Dmgvht/GC3 5RYVDSwTAxkyTN58m82hMU8KppzqVeXj2ezL9wSleIuIt4jK4Weyyy5IjxM8EXUCEkL1 dzmtJKwNqzA6roKQaw7P5j1ozwM4ULV7jR3s2mapg2VEb3pwbzIEVDQ+y/zblmOpKVJ4 Qj8oad44HSj239J366Ho2MXR8NQqzgqxL/WaNZHfJyCfpO6L3Gx6CroQtQ/IKgA+UPG/ R2RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=rN2S1v3/1BoBol8adRSL3kZXLWS4doEk15964RDMi4c=; b=Kkdi/qyto/Vu5Y/t+arw0cCWaYVfaCw8qnWdYaUocTiN7wvMuBstPVh5K14ol11eDS Z9ofAgqxV3lPG6ccUYZnWEOzxPmal+NbDj/nKjzLnbeufs0cENjhWJDBgdmNk3yjdCvS ThIuJDRio05hlmJihlEqD5saPctcsZRes3NkEKtBj0WESFQsHzSgmbEW6PZLVDiKHEwl 4S4OD6i3+eLcFccwk51InnFq56L1Ct2cwdmyLEBjZRE0YLhWGuoEmPaCdO3S1gaqLmZr M2RHHuSUNKc4TAfCXVeeTPT6vgWudjJNpyhrOFMGcbdLtmiSMMhbZWIdy3q+h1+KQdas iS8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EnZ9xP+r; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a27si9630344pfg.105.2019.09.01.20.56.19; Sun, 01 Sep 2019 20:57:12 -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=@linaro.org header.s=google header.b=EnZ9xP+r; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729293AbfIBDo3 (ORCPT + 99 others); Sun, 1 Sep 2019 23:44:29 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36462 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfIBDo3 (ORCPT ); Sun, 1 Sep 2019 23:44:29 -0400 Received: by mail-pg1-f196.google.com with SMTP id l21so6714482pgm.3 for ; Sun, 01 Sep 2019 20:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=rN2S1v3/1BoBol8adRSL3kZXLWS4doEk15964RDMi4c=; b=EnZ9xP+rSm8ScoPmKeP/EQoxVAJ9I+RcI3ej3gKp3qnvXSqp8ssZhibEEokG6LxKmT dKWYDoPlAlf+2YXSp0X8dh7J6wJ2TosV1OZJkR4bvoso+kMi5OsVXPeVOlpqdqtHX8a9 ezJ2PMroj/n6N296V5VlkYMvZ8lLgz0q31AkHdotjmI9cb5y/ehlxLkqyxl0E2G8tMFA oKC95J280UI37Efb3vbQOwti8EKZPrTy0oUXs/ahK8R/ym0Irb0KY8M7BYP5oAz/qZYW +D196au6k86FHrP/j3wRMAsO4iV9U+/EMZB5fgzcViMgu01qOig0TXTr4Z+JyqwVLyE4 CdfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=rN2S1v3/1BoBol8adRSL3kZXLWS4doEk15964RDMi4c=; b=HbnsFmTmPwi+6pN03vE6uVq4SkD5GUAHRh2RohG347gKIb+HZlpOHjv+WJHnRmv/Ho g/CF54FwQdvBMcBVsltTuaajRHvFK7RM4EcShOOyUSNPoukSNTmSMxoPwnbA8RazjRmK +clpiGrLA/1IYf7NpLJnNu7kYayjpX0rNAM621l/kKRfo4tA245+AxwfUnev6sHoxwGk mx5eB6AltIMsiJAqKEAl6MAOrwVplt7V5IIWeJPACIY6s19XHQVbJotDY3ugUEKtjCPH JSAx+hndwzs+Jfl1/Fx9EFUNtg5Kc+wlPl+sg3NcvoZSd8Az42e+WaPBn0q8FZ5G6aGr 4S4Q== X-Gm-Message-State: APjAAAWnSkKT/uikCqlOD4X+9FE0DExnRFGNjOIpNe+cbChZyn/4XCwU i35wtKD6g/p/2KKcifa/eAKGCg== X-Received: by 2002:a17:90a:d149:: with SMTP id t9mr11457048pjw.58.1567395868605; Sun, 01 Sep 2019 20:44:28 -0700 (PDT) Received: from ?IPv6:240e:362:407:a700:853f:6246:6ef0:b4ae? ([240e:362:407:a700:853f:6246:6ef0:b4ae]) by smtp.gmail.com with ESMTPSA id c12sm19051624pfc.22.2019.09.01.20.44.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Sep 2019 20:44:28 -0700 (PDT) Subject: Re: [PATCH v2 2/2] uacce: add uacce driver From: zhangfei To: Greg Kroah-Hartman Cc: Arnd Bergmann , jonathan.cameron@huawei.com, kenneth-lee-2012@foxmail.com, Wangzhou , linux-accelerators@lists.ozlabs.org, linux-kernel@vger.kernel.org, Kenneth Lee , Zaibo Xu References: <1566998876-31770-1-git-send-email-zhangfei.gao@linaro.org> <1566998876-31770-3-git-send-email-zhangfei.gao@linaro.org> <20190828152201.GA10163@kroah.com> <5c2b0889-ea05-1ecd-fe5b-40611bd31945@linaro.org> <20190829095439.GA13915@kroah.com> <39f792df-e3e3-eaa6-f78b-bf325b79f1b7@linaro.org> Message-ID: Date: Mon, 2 Sep 2019 11:44:16 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <39f792df-e3e3-eaa6-f78b-bf325b79f1b7@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Greg On 2019/8/30 下午10:54, zhangfei wrote: >>> On 2019/8/28 下午11:22, Greg Kroah-Hartman wrote: >>>> On Wed, Aug 28, 2019 at 09:27:56PM +0800, Zhangfei Gao wrote: >>>>> +struct uacce { >>>>> +    const char *drv_name; >>>>> +    const char *algs; >>>>> +    const char *api_ver; >>>>> +    unsigned int flags; >>>>> +    unsigned long qf_pg_start[UACCE_QFRT_MAX]; >>>>> +    struct uacce_ops *ops; >>>>> +    struct device *pdev; >>>>> +    bool is_vf; >>>>> +    u32 dev_id; >>>>> +    struct cdev cdev; >>>>> +    struct device dev; >>>>> +    void *priv; >>>>> +    atomic_t state; >>>>> +    int prot; >>>>> +    struct mutex q_lock; >>>>> +    struct list_head qs; >>>>> +}; >>>> At a quick glance, this problem really stood out to me.  You CAN NOT >>>> have two different objects within a structure that have different >>>> lifetime rules and reference counts.  You do that here with both a >>>> 'struct cdev' and a 'struct device'.  Pick one or the other, but never >>>> both. >>>> >>>> I would recommend using a 'struct device' and then a 'struct cdev *'. >>>> That way you get the advantage of using the driver model properly, and >>>> then just adding your char device node pointer to "the side" which >>>> interacts with this device. >>>> >>>> Then you might want to call this "struct uacce_device" :) I think I understand now. 'struct device' and then a 'struct cdev' have different refcounts. Using 'struct cdev *', the release is not in uacce.c, but controlled by cdev itself. So uacce is decoupled with cdev. //Using 'struct cdev *' cdev_alloc->cdev_dynamic_release:kfree(p); uacce_destroy_chrdev: cdev_device_del->cdev_del(cdev)->kobject_put(&p->kobj); if (refcount--) == 0 cdev_dynamic_release->kfree(p); //Using 'struct device' cdev_init->cdev_default_release cdev is freed in uacce.c, So 'struct device' and then a 'struct cdev' are bind together, while cdev and uacce->dev have different refcount. Thanks for the patience.