From owner-svn-src-head@freebsd.org Tue May 24 07:06:05 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C72DFB48F5B; Tue, 24 May 2016 07:06:05 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7EFBC1391; Tue, 24 May 2016 07:06:05 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4O764h1072999; Tue, 24 May 2016 07:06:04 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4O7644X072998; Tue, 24 May 2016 07:06:04 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201605240706.u4O7644X072998@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 24 May 2016 07:06:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300575 - head/sys/compat/linuxkpi/common/include/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2016 07:06:05 -0000 Author: hselasky Date: Tue May 24 07:06:04 2016 New Revision: 300575 URL: https://svnweb.freebsd.org/changeset/base/300575 Log: Use make_dev_s() instead of make_dev() to avoid race setting "si_drv1". Convert panic() into regular error while at it. Suggested by: jhb @ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/cdev.h Modified: head/sys/compat/linuxkpi/common/include/linux/cdev.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/cdev.h Tue May 24 06:42:14 2016 (r300574) +++ head/sys/compat/linuxkpi/common/include/linux/cdev.h Tue May 24 07:06:04 2016 (r300575) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -80,12 +80,27 @@ cdev_put(struct linux_cdev *p) static inline int cdev_add(struct linux_cdev *cdev, dev_t dev, unsigned count) { + struct make_dev_args args; + int error; + if (count != 1) - panic("cdev_add: Unsupported count: %d", count); - cdev->cdev = make_dev(&linuxcdevsw, MINOR(dev), 0, 0, 0700, - "%s", kobject_name(&cdev->kobj)); + return (-EINVAL); + cdev->dev = dev; - cdev->cdev->si_drv1 = cdev; + + /* Setup arguments for make_dev_s() */ + make_dev_args_init(&args); + args.mda_devsw = &linuxcdevsw; + args.mda_uid = 0; + args.mda_gid = 0; + args.mda_mode = 0700; + args.mda_si_drv1 = cdev; + args.mda_unit = MINOR(dev); + + error = make_dev_s(&args, &cdev->cdev, "%s", + kobject_name(&cdev->kobj)); + if (error) + return (-error); kobject_get(cdev->kobj.parent); return (0); @@ -94,10 +109,24 @@ cdev_add(struct linux_cdev *cdev, dev_t static inline int cdev_add_ext(struct linux_cdev *cdev, dev_t dev, uid_t uid, gid_t gid, int mode) { - cdev->cdev = make_dev(&linuxcdevsw, MINOR(dev), uid, gid, mode, - "%s/%d", kobject_name(&cdev->kobj), MINOR(dev)); + struct make_dev_args args; + int error; + cdev->dev = dev; - cdev->cdev->si_drv1 = cdev; + + /* Setup arguments for make_dev_s() */ + make_dev_args_init(&args); + args.mda_devsw = &linuxcdevsw; + args.mda_uid = uid; + args.mda_gid = gid; + args.mda_mode = mode; + args.mda_si_drv1 = cdev; + args.mda_unit = MINOR(dev); + + error = make_dev_s(&args, &cdev->cdev, "%s/%d", + kobject_name(&cdev->kobj), MINOR(dev)); + if (error) + return (-error); kobject_get(cdev->kobj.parent); return (0);