115dba7a9SFrançois Tigeot /*
2*1dedbd3bSFrançois Tigeot * Copyright (c) 2018-2019 François Tigeot <ftigeot@wolfpond.org>
315dba7a9SFrançois Tigeot * All rights reserved.
415dba7a9SFrançois Tigeot *
515dba7a9SFrançois Tigeot * Redistribution and use in source and binary forms, with or without
615dba7a9SFrançois Tigeot * modification, are permitted provided that the following conditions
715dba7a9SFrançois Tigeot * are met:
815dba7a9SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
915dba7a9SFrançois Tigeot * notice unmodified, this list of conditions, and the following
1015dba7a9SFrançois Tigeot * disclaimer.
1115dba7a9SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
1215dba7a9SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
1315dba7a9SFrançois Tigeot * documentation and/or other materials provided with the distribution.
1415dba7a9SFrançois Tigeot *
1515dba7a9SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1615dba7a9SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1715dba7a9SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1815dba7a9SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1915dba7a9SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2015dba7a9SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2115dba7a9SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2215dba7a9SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2315dba7a9SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2415dba7a9SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2515dba7a9SFrançois Tigeot */
2615dba7a9SFrançois Tigeot
278b44ed4dSzrj #include <linux/gfp.h>
2815dba7a9SFrançois Tigeot #include <linux/kobject.h>
2915dba7a9SFrançois Tigeot
kobject_init_and_add(struct kobject * kobj,struct kobj_type * ktype,struct kobject * parent,const char * fmt,...)3015dba7a9SFrançois Tigeot int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
3115dba7a9SFrançois Tigeot struct kobject *parent, const char *fmt, ...)
3215dba7a9SFrançois Tigeot {
3315dba7a9SFrançois Tigeot va_list ap;
3415dba7a9SFrançois Tigeot
3515dba7a9SFrançois Tigeot kobj->ktype = ktype;
3615dba7a9SFrançois Tigeot kref_init(&kobj->kref);
3715dba7a9SFrançois Tigeot
389286b91eSSascha Wildner va_start(ap, fmt);
39*1dedbd3bSFrançois Tigeot kobj->name = kvasprintf(M_WAITOK, fmt, ap);
409286b91eSSascha Wildner va_end(ap);
4115dba7a9SFrançois Tigeot
4215dba7a9SFrançois Tigeot return 0;
4315dba7a9SFrançois Tigeot }
4415dba7a9SFrançois Tigeot
kobject_release(struct kref * kref)4515dba7a9SFrançois Tigeot void kobject_release(struct kref *kref)
4615dba7a9SFrançois Tigeot {
4715dba7a9SFrançois Tigeot struct kobject *kobj = container_of(kref, struct kobject, kref);
4815dba7a9SFrançois Tigeot
4915dba7a9SFrançois Tigeot if (kobj->ktype && kobj->ktype->release)
5015dba7a9SFrançois Tigeot kobj->ktype->release(kobj);
5115dba7a9SFrançois Tigeot }
52