From owner-dev-commits-src-all@freebsd.org Wed Jun 2 12:24:59 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 41AFA642042; Wed, 2 Jun 2021 12:24:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fw7Wt6NcDz3FgT; Wed, 2 Jun 2021 12:24:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B288416C55; Wed, 2 Jun 2021 12:24:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 152COwO9019297; Wed, 2 Jun 2021 12:24:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152COwi8019296; Wed, 2 Jun 2021 12:24:58 GMT (envelope-from git) Date: Wed, 2 Jun 2021 12:24:58 GMT Message-Id: <202106021224.152COwi8019296@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: fba2292d65e0 - stable/13 - Implement cdev_device_add() and cdev_device_del() in the LinuxKPI. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fba2292d65e04d3a07eb5d089f511f230d344ac8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 12:24:59 -0000 The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=fba2292d65e04d3a07eb5d089f511f230d344ac8 commit fba2292d65e04d3a07eb5d089f511f230d344ac8 Author: Hans Petter Selasky AuthorDate: 2021-05-11 18:51:59 +0000 Commit: Hans Petter Selasky CommitDate: 2021-06-02 11:25:20 +0000 Implement cdev_device_add() and cdev_device_del() in the LinuxKPI. Sponsored by: Mellanox Technologies // NVIDIA Networking (cherry picked from commit b8f113cab91f288e5d5e29d21184d1601b87cfdd) --- sys/compat/linuxkpi/common/include/linux/cdev.h | 11 ++++++- sys/compat/linuxkpi/common/src/linux_compat.c | 38 ++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/cdev.h b/sys/compat/linuxkpi/common/include/linux/cdev.h index bdfb7e76c9a7..39a65472e921 100644 --- a/sys/compat/linuxkpi/common/include/linux/cdev.h +++ b/sys/compat/linuxkpi/common/include/linux/cdev.h @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ #include +struct device; struct file_operations; struct inode; struct module; @@ -143,6 +144,14 @@ cdev_del(struct linux_cdev *cdev) struct linux_cdev *linux_find_cdev(const char *name, unsigned major, unsigned minor); +int linux_cdev_device_add(struct linux_cdev *, struct device *); +void linux_cdev_device_del(struct linux_cdev *, struct device *); + +#define cdev_device_add(...) \ + linux_cdev_device_add(__VA_ARGS__) +#define cdev_device_del(...) \ + linux_cdev_device_del(__VA_ARGS__) + #define cdev linux_cdev #endif /* _LINUX_CDEV_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 35535eb75abb..0fc0ad702788 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2018 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -2235,6 +2235,42 @@ linux_cdev_static_release(struct kobject *kobj) kobject_put(kobj->parent); } +int +linux_cdev_device_add(struct linux_cdev *ldev, struct device *dev) +{ + int ret; + + if (dev->devt != 0) { + /* Set parent kernel object. */ + ldev->kobj.parent = &dev->kobj; + + /* + * Unlike Linux we require the kobject of the + * character device structure to have a valid name + * before calling this function: + */ + if (ldev->kobj.name == NULL) + return (-EINVAL); + + ret = cdev_add(ldev, dev->devt, 1); + if (ret) + return (ret); + } + ret = device_add(dev); + if (ret != 0 && dev->devt != 0) + cdev_del(ldev); + return (ret); +} + +void +linux_cdev_device_del(struct linux_cdev *ldev, struct device *dev) +{ + device_del(dev); + + if (dev->devt != 0) + cdev_del(ldev); +} + static void linux_destroy_dev(struct linux_cdev *ldev) {