From owner-svn-src-all@freebsd.org Mon May 16 16:31:44 2016 Return-Path: Delivered-To: svn-src-all@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 3B575B3D183; Mon, 16 May 2016 16:31:44 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-io0-x241.google.com (mail-io0-x241.google.com [IPv6:2607:f8b0:4001:c06::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 03E6E17BD; Mon, 16 May 2016 16:31:44 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: by mail-io0-x241.google.com with SMTP id i75so15869576ioa.2; Mon, 16 May 2016 09:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=iMswHq+LOzRdOoCfppXlrEdEgeNMQInk/4UzuhBJjX4=; b=J8ADuaogBA1BkVGAbhnYTNZkBxB9IcEU2+FftsiSRpMCIx1lUZx2Y8pa4xKl2/Wuol FY3OTRqsisSY+mtOyEEeLLY8+ZKa938rkM2/+wqvSRtGFih7L2xKhahCwqrdrAqxgqL+ WLLWxPlo5eUQb9ciZwGUYv8zJwy1mjntuZrwwDq3HFuuhYCHKTqTQ41vji4fIWH4J0V4 cFkJTFRbiSSNLAPLUR1ye96lpmaHlj3aqm2Iw4bfGIwZf+uFQp6Q2Aho1EWDeF9f+EHH mUD/b4mR9ZS1ThTF8WtUY8lqQcZY38hnSNMo6rb295CpYGWMGqZQ96bjTeLZa083jE3z WfNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=iMswHq+LOzRdOoCfppXlrEdEgeNMQInk/4UzuhBJjX4=; b=ifoYnwEHtmNHJfFP8p78B32DaRljCuHW0FsN27BgYC7lafDyJiZ0GmBqb644/t5OUC IVsCLW712vnwm9ZnJjpm1hLlr9g/nIadFTwL6kad0TVD9EhJlIDxGhl+1zeHG6KBMaUE Mg+3rtkln0n4X+gSr9kwbPCheSwxdmRBaddsOoOpdW9YH7cWIGfW/bovjZjDT9GAr6g1 lJzxcbC86K8qZzQbtzEg4WfDL8QQIbXwQ+3mo/OiuC0Zf+by2ZrQSeA9NfDtffXlKdT7 MPePxvFcb+vn9Wubg70+ViuoHecBVpHlaVQN6xpz0L1SHYcvz0jlP91Ryc5iQbd9pUK5 cEzA== X-Gm-Message-State: AOPr4FX6ziGOfw1gwXg4Dn2jvxiEKPP0ZXVLBax1Jt+fGYSyaY8S26+V8Zs1uOphr5T/KA== X-Received: by 10.107.182.137 with SMTP id g131mr20621339iof.27.1463416303425; Mon, 16 May 2016 09:31:43 -0700 (PDT) Received: from [192.168.20.7] (c-73-97-222-46.hsd1.wa.comcast.net. [73.97.222.46]) by smtp.gmail.com with ESMTPSA id v136sm5673862ita.3.2016.05.16.09.31.42 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 May 2016 09:31:42 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: svn commit: r299933 - in head/sys: compat/linuxkpi/common/include/linux sys From: "Ngie Cooper (yaneurabeya)" In-Reply-To: <201605160956.u4G9umAT025380@repo.freebsd.org> Date: Mon, 16 May 2016 09:31:41 -0700 Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <222500EB-85C1-4FF7-ADB9-0BD71F55D835@gmail.com> References: <201605160956.u4G9umAT025380@repo.freebsd.org> To: Hans Petter Selasky X-Mailer: Apple Mail (2.3124) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 16:31:44 -0000 > On May 16, 2016, at 02:56, Hans Petter Selasky = wrote: >=20 > Author: hselasky > Date: Mon May 16 09:56:48 2016 > New Revision: 299933 > URL: https://svnweb.freebsd.org/changeset/base/299933 >=20 > Log: > Implement more Linux device related functions in the LinuxKPI. While > at it use NULL for some pointer checks. >=20 > Bump the FreeBSD version to force recompilation of all kernel modules > due to a structure size change. >=20 > Obtained from: kmacy @ > MFC after: 1 week > Sponsored by: Mellanox Technologies >=20 > Modified: > head/sys/compat/linuxkpi/common/include/linux/device.h > head/sys/sys/param.h >=20 > Modified: head/sys/compat/linuxkpi/common/include/linux/device.h > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/compat/linuxkpi/common/include/linux/device.h Mon May = 16 09:31:44 2016 (r299932) > +++ head/sys/compat/linuxkpi/common/include/linux/device.h Mon May = 16 09:56:48 2016 (r299933) > @@ -31,6 +31,7 @@ > #ifndef _LINUX_DEVICE_H_ > #define _LINUX_DEVICE_H_ >=20 > +#include > #include > #include > #include > @@ -71,6 +72,7 @@ struct device { > unsigned int irq; > unsigned int msix; > unsigned int msix_max; > + const struct attribute_group **groups; > }; >=20 > extern struct device linux_root_device; > @@ -127,11 +129,12 @@ show_class_attr_string(struct class *cla > #define dev_err(dev, fmt, ...) device_printf((dev)->bsddev, = fmt, ##__VA_ARGS__) > #define dev_warn(dev, fmt, ...) device_printf((dev)->bsddev, = fmt, ##__VA_ARGS__) > #define dev_info(dev, fmt, ...) device_printf((dev)->bsddev, = fmt, ##__VA_ARGS__) > +#define dev_notice(dev, fmt, ...) = device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) > #define dev_printk(lvl, dev, fmt, ...) = \ > device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) >=20 > static inline void * > -dev_get_drvdata(struct device *dev) > +dev_get_drvdata(const struct device *dev) > { >=20 > return dev->driver_data; > @@ -191,11 +194,106 @@ class_unregister(struct class *class) > kobject_put(&class->kobj); > } >=20 > +static inline struct device *kobj_to_dev(struct kobject *kobj) > +{ > + return container_of(kobj, struct device, kobj); > +} > + > /* > - * Devices are registered and created for exporting to sysfs. create > + * Devices are registered and created for exporting to sysfs. Create > * implies register and register assumes the device fields have been > * setup appropriately before being called. > */ > +static inline void > +device_initialize(struct device *dev) > +{ > + device_t bsddev; > + > + bsddev =3D NULL; > + if (dev->devt) { > + int unit =3D MINOR(dev->devt); > + bsddev =3D devclass_get_device(dev->class->bsdclass, = unit); > + } > + if (bsddev !=3D NULL) > + device_set_softc(bsddev, dev); > + > + dev->bsddev =3D bsddev; > + kobject_init(&dev->kobj, &linux_dev_ktype); > +} > + > +static inline int > +device_add(struct device *dev) > +{=09 > + if (dev->bsddev !=3D NULL) { > + if (dev->devt =3D=3D 0) > + dev->devt =3D makedev(0, = device_get_unit(dev->bsddev)); > + } > + kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev)); > + return (0); > +} > + > +static inline void > +device_create_release(struct device *dev) > +{ > + kfree(dev); > +} > + > +static inline struct device * > +device_create_groups_vargs(struct class *class, struct device = *parent, > + dev_t devt, void *drvdata, const struct attribute_group **groups, > + const char *fmt, va_list args) > +{ > + struct device *dev =3D NULL; > + int retval =3D -ENODEV; > + > + if (class =3D=3D NULL || IS_ERR(class)) > + goto error; > + > + dev =3D kzalloc(sizeof(*dev), GFP_KERNEL); > + if (!dev) { > + retval =3D -ENOMEM; > + goto error; > + } > + > + device_initialize(dev); > + dev->devt =3D devt; > + dev->class =3D class; > + dev->parent =3D parent; > + dev->groups =3D groups; > + dev->release =3D device_create_release; > + dev->bsddev =3D devclass_get_device(dev->class->bsdclass, = MINOR(devt)); > + dev_set_drvdata(dev, drvdata); > + > + retval =3D kobject_set_name_vargs(&dev->kobj, fmt, args); > + if (retval) > + goto error; > + > + retval =3D device_add(dev); > + if (retval) > + goto error; > + > + return dev; > + > +error: > + put_device(dev); > + return ERR_PTR(retval); > +} > + > +static inline struct device * > +device_create_with_groups(struct class *class, > + struct device *parent, dev_t devt, void *drvdata, > + const struct attribute_group **groups, const char *fmt, ...) > +{ > + va_list vargs; > + struct device *dev; > + > + va_start(vargs, fmt); > + dev =3D device_create_groups_vargs(class, parent, devt, drvdata, > + groups, fmt, vargs); > + va_end(vargs); > + return dev; > +} > + > static inline int > device_register(struct device *dev) > { > @@ -233,13 +331,29 @@ device_unregister(struct device *dev) > device_t bsddev; >=20 > bsddev =3D dev->bsddev; > + dev->bsddev =3D NULL; > + > mtx_lock(&Giant); > - if (bsddev) > + if (bsddev !=3D NULL) Dumb question =E2=80=94 couldn=E2=80=99t we run the check without = locking Giant, then delete the child, e.g. if (bsddev !=3D NULL) { mtx_lock(&Giant); device_delete_child(device_get_parent(bsddev), bsddev);=20 mtx_unlock(&Giant); } put_device(dev); > device_delete_child(device_get_parent(bsddev), bsddev); > mtx_unlock(&Giant); > put_device(dev); > } >=20 > +static inline void > +device_del(struct device *dev) > +{ > + device_t bsddev; > + > + bsddev =3D dev->bsddev; > + dev->bsddev =3D NULL; > + > + mtx_lock(&Giant); > + if (bsddev !=3D NULL) > + device_delete_child(device_get_parent(bsddev), bsddev); > + mtx_unlock(&Giant); > +} > + > struct device *device_create(struct class *class, struct device = *parent, > dev_t devt, void *drvdata, const char *fmt, ...); >=20 > @@ -251,7 +365,7 @@ device_destroy(struct class *class, dev_ >=20 > unit =3D MINOR(devt); > bsddev =3D devclass_get_device(class->bsdclass, unit); > - if (bsddev) > + if (bsddev !=3D NULL) > device_unregister(device_get_softc(bsddev)); > } >=20 >=20 > Modified: head/sys/sys/param.h > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/sys/param.h Mon May 16 09:31:44 2016 = (r299932) > +++ head/sys/sys/param.h Mon May 16 09:56:48 2016 = (r299933) > @@ -58,7 +58,7 @@ > * in the range 5 to 9. > */ > #undef __FreeBSD_version > -#define __FreeBSD_version 1100108 /* Master, propagated to newvers = */ > +#define __FreeBSD_version 1100109 /* Master, propagated to newvers = */ >=20 > /* > * __FreeBSD_kernel__ indicates that this system uses the kernel of = FreeBSD, >=20