Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
95e07832
Commit
95e07832
authored
Aug 02, 2004
by
Greg Kroah-Hartman
Browse files
Options
Browse Files
Download
Plain Diff
Merge gregkh@kernel.bkbits.net:linux/driver-2.6
into kroah.com:/home/greg/linux/BK/driver-2.6
parents
a5cd4546
00552a1f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
94 additions
and
103 deletions
+94
-103
drivers/scsi/sd.c
drivers/scsi/sd.c
+4
-4
drivers/scsi/sr.c
drivers/scsi/sr.c
+4
-4
drivers/usb/core/config.c
drivers/usb/core/config.c
+4
-3
drivers/usb/core/message.c
drivers/usb/core/message.c
+1
-1
drivers/usb/core/urb.c
drivers/usb/core/urb.c
+2
-2
drivers/usb/core/usb.h
drivers/usb/core/usb.h
+1
-0
drivers/usb/host/ehci-mem.c
drivers/usb/host/ehci-mem.c
+2
-2
drivers/usb/serial/usb-serial.c
drivers/usb/serial/usb-serial.c
+62
-68
include/linux/kref.h
include/linux/kref.h
+2
-5
lib/kref.c
lib/kref.c
+12
-14
No files found.
drivers/scsi/sd.c
View file @
95e07832
...
@@ -188,7 +188,7 @@ static struct scsi_disk *scsi_disk_get(struct gendisk *disk)
...
@@ -188,7 +188,7 @@ static struct scsi_disk *scsi_disk_get(struct gendisk *disk)
return
sdkp
;
return
sdkp
;
out_put:
out_put:
kref_put
(
&
sdkp
->
kref
);
kref_put
(
&
sdkp
->
kref
,
scsi_disk_release
);
out_sdkp:
out_sdkp:
sdkp
=
NULL
;
sdkp
=
NULL
;
out:
out:
...
@@ -200,7 +200,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
...
@@ -200,7 +200,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
{
{
down
(
&
sd_ref_sem
);
down
(
&
sd_ref_sem
);
scsi_device_put
(
sdkp
->
device
);
scsi_device_put
(
sdkp
->
device
);
kref_put
(
&
sdkp
->
kref
);
kref_put
(
&
sdkp
->
kref
,
scsi_disk_release
);
up
(
&
sd_ref_sem
);
up
(
&
sd_ref_sem
);
}
}
...
@@ -1362,7 +1362,7 @@ static int sd_probe(struct device *dev)
...
@@ -1362,7 +1362,7 @@ static int sd_probe(struct device *dev)
goto
out
;
goto
out
;
memset
(
sdkp
,
0
,
sizeof
(
*
sdkp
));
memset
(
sdkp
,
0
,
sizeof
(
*
sdkp
));
kref_init
(
&
sdkp
->
kref
,
scsi_disk_release
);
kref_init
(
&
sdkp
->
kref
);
/* Note: We can accomodate 64 partitions, but the genhd code
/* Note: We can accomodate 64 partitions, but the genhd code
* assumes partitions allocate consecutive minors, which they don't.
* assumes partitions allocate consecutive minors, which they don't.
...
@@ -1464,7 +1464,7 @@ static int sd_remove(struct device *dev)
...
@@ -1464,7 +1464,7 @@ static int sd_remove(struct device *dev)
del_gendisk
(
sdkp
->
disk
);
del_gendisk
(
sdkp
->
disk
);
sd_shutdown
(
dev
);
sd_shutdown
(
dev
);
down
(
&
sd_ref_sem
);
down
(
&
sd_ref_sem
);
kref_put
(
&
sdkp
->
kref
);
kref_put
(
&
sdkp
->
kref
,
scsi_disk_release
);
up
(
&
sd_ref_sem
);
up
(
&
sd_ref_sem
);
return
0
;
return
0
;
...
...
drivers/scsi/sr.c
View file @
95e07832
...
@@ -147,7 +147,7 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
...
@@ -147,7 +147,7 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
goto
out
;
goto
out
;
out_put:
out_put:
kref_put
(
&
cd
->
kref
);
kref_put
(
&
cd
->
kref
,
sr_kref_release
);
out_null:
out_null:
cd
=
NULL
;
cd
=
NULL
;
out:
out:
...
@@ -159,7 +159,7 @@ static inline void scsi_cd_put(struct scsi_cd *cd)
...
@@ -159,7 +159,7 @@ static inline void scsi_cd_put(struct scsi_cd *cd)
{
{
down
(
&
sr_ref_sem
);
down
(
&
sr_ref_sem
);
scsi_device_put
(
cd
->
device
);
scsi_device_put
(
cd
->
device
);
kref_put
(
&
cd
->
kref
);
kref_put
(
&
cd
->
kref
,
sr_kref_release
);
up
(
&
sr_ref_sem
);
up
(
&
sr_ref_sem
);
}
}
...
@@ -576,7 +576,7 @@ static int sr_probe(struct device *dev)
...
@@ -576,7 +576,7 @@ static int sr_probe(struct device *dev)
goto
fail
;
goto
fail
;
memset
(
cd
,
0
,
sizeof
(
*
cd
));
memset
(
cd
,
0
,
sizeof
(
*
cd
));
kref_init
(
&
cd
->
kref
,
sr_kref_release
);
kref_init
(
&
cd
->
kref
);
disk
=
alloc_disk
(
1
);
disk
=
alloc_disk
(
1
);
if
(
!
disk
)
if
(
!
disk
)
...
@@ -937,7 +937,7 @@ static int sr_remove(struct device *dev)
...
@@ -937,7 +937,7 @@ static int sr_remove(struct device *dev)
del_gendisk
(
cd
->
disk
);
del_gendisk
(
cd
->
disk
);
down
(
&
sr_ref_sem
);
down
(
&
sr_ref_sem
);
kref_put
(
&
cd
->
kref
);
kref_put
(
&
cd
->
kref
,
sr_kref_release
);
up
(
&
sr_ref_sem
);
up
(
&
sr_ref_sem
);
return
0
;
return
0
;
...
...
drivers/usb/core/config.c
View file @
95e07832
...
@@ -106,7 +106,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
...
@@ -106,7 +106,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
return
buffer
-
buffer0
+
i
;
return
buffer
-
buffer0
+
i
;
}
}
static
void
usb_release_interface_cache
(
struct
kref
*
ref
)
void
usb_release_interface_cache
(
struct
kref
*
ref
)
{
{
struct
usb_interface_cache
*
intfc
=
ref_to_usb_interface_cache
(
ref
);
struct
usb_interface_cache
*
intfc
=
ref_to_usb_interface_cache
(
ref
);
int
j
;
int
j
;
...
@@ -356,7 +356,7 @@ int usb_parse_configuration(struct device *ddev, int cfgidx,
...
@@ -356,7 +356,7 @@ int usb_parse_configuration(struct device *ddev, int cfgidx,
if
(
!
intfc
)
if
(
!
intfc
)
return
-
ENOMEM
;
return
-
ENOMEM
;
memset
(
intfc
,
0
,
len
);
memset
(
intfc
,
0
,
len
);
kref_init
(
&
intfc
->
ref
,
usb_release_interface_cache
);
kref_init
(
&
intfc
->
ref
);
}
}
/* Skip over any Class Specific or Vendor Specific descriptors;
/* Skip over any Class Specific or Vendor Specific descriptors;
...
@@ -422,7 +422,8 @@ void usb_destroy_configuration(struct usb_device *dev)
...
@@ -422,7 +422,8 @@ void usb_destroy_configuration(struct usb_device *dev)
for
(
i
=
0
;
i
<
cf
->
desc
.
bNumInterfaces
;
i
++
)
{
for
(
i
=
0
;
i
<
cf
->
desc
.
bNumInterfaces
;
i
++
)
{
if
(
cf
->
intf_cache
[
i
])
if
(
cf
->
intf_cache
[
i
])
kref_put
(
&
cf
->
intf_cache
[
i
]
->
ref
);
kref_put
(
&
cf
->
intf_cache
[
i
]
->
ref
,
usb_release_interface_cache
);
}
}
}
}
kfree
(
dev
->
config
);
kfree
(
dev
->
config
);
...
...
drivers/usb/core/message.c
View file @
95e07832
...
@@ -1195,7 +1195,7 @@ static void release_interface(struct device *dev)
...
@@ -1195,7 +1195,7 @@ static void release_interface(struct device *dev)
struct
usb_interface_cache
*
intfc
=
struct
usb_interface_cache
*
intfc
=
altsetting_to_usb_interface_cache
(
intf
->
altsetting
);
altsetting_to_usb_interface_cache
(
intf
->
altsetting
);
kref_put
(
&
intfc
->
ref
);
kref_put
(
&
intfc
->
ref
,
usb_release_interface_cache
);
kfree
(
intf
);
kfree
(
intf
);
}
}
...
...
drivers/usb/core/urb.c
View file @
95e07832
...
@@ -39,7 +39,7 @@ void usb_init_urb(struct urb *urb)
...
@@ -39,7 +39,7 @@ void usb_init_urb(struct urb *urb)
{
{
if
(
urb
)
{
if
(
urb
)
{
memset
(
urb
,
0
,
sizeof
(
*
urb
));
memset
(
urb
,
0
,
sizeof
(
*
urb
));
kref_init
(
&
urb
->
kref
,
urb_destroy
);
kref_init
(
&
urb
->
kref
);
spin_lock_init
(
&
urb
->
lock
);
spin_lock_init
(
&
urb
->
lock
);
}
}
}
}
...
@@ -88,7 +88,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags)
...
@@ -88,7 +88,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags)
void
usb_free_urb
(
struct
urb
*
urb
)
void
usb_free_urb
(
struct
urb
*
urb
)
{
{
if
(
urb
)
if
(
urb
)
kref_put
(
&
urb
->
kref
);
kref_put
(
&
urb
->
kref
,
urb_destroy
);
}
}
/**
/**
...
...
drivers/usb/core/usb.h
View file @
95e07832
...
@@ -10,6 +10,7 @@ extern int usb_unbind_interface (struct device *dev);
...
@@ -10,6 +10,7 @@ extern int usb_unbind_interface (struct device *dev);
extern
void
usb_disable_endpoint
(
struct
usb_device
*
dev
,
unsigned
int
epaddr
);
extern
void
usb_disable_endpoint
(
struct
usb_device
*
dev
,
unsigned
int
epaddr
);
extern
void
usb_disable_interface
(
struct
usb_device
*
dev
,
extern
void
usb_disable_interface
(
struct
usb_device
*
dev
,
struct
usb_interface
*
intf
);
struct
usb_interface
*
intf
);
extern
void
usb_release_interface_cache
(
struct
kref
*
ref
);
extern
void
usb_disable_device
(
struct
usb_device
*
dev
,
int
skip_ep0
);
extern
void
usb_disable_device
(
struct
usb_device
*
dev
,
int
skip_ep0
);
extern
void
usb_enable_endpoint
(
struct
usb_device
*
dev
,
extern
void
usb_enable_endpoint
(
struct
usb_device
*
dev
,
...
...
drivers/usb/host/ehci-mem.c
View file @
95e07832
...
@@ -114,7 +114,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
...
@@ -114,7 +114,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
return
qh
;
return
qh
;
memset
(
qh
,
0
,
sizeof
*
qh
);
memset
(
qh
,
0
,
sizeof
*
qh
);
kref_init
(
&
qh
->
kref
,
qh_destroy
);
kref_init
(
&
qh
->
kref
);
qh
->
ehci
=
ehci
;
qh
->
ehci
=
ehci
;
qh
->
qh_dma
=
dma
;
qh
->
qh_dma
=
dma
;
// INIT_LIST_HEAD (&qh->qh_list);
// INIT_LIST_HEAD (&qh->qh_list);
...
@@ -139,7 +139,7 @@ static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
...
@@ -139,7 +139,7 @@ static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
static
inline
void
qh_put
(
struct
ehci_qh
*
qh
)
static
inline
void
qh_put
(
struct
ehci_qh
*
qh
)
{
{
kref_put
(
&
qh
->
kref
);
kref_put
(
&
qh
->
kref
,
qh_destroy
);
}
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
...
...
drivers/usb/serial/usb-serial.c
View file @
95e07832
...
@@ -421,6 +421,63 @@ static void return_serial (struct usb_serial *serial)
...
@@ -421,6 +421,63 @@ static void return_serial (struct usb_serial *serial)
return
;
return
;
}
}
static
void
destroy_serial
(
struct
kref
*
kref
)
{
struct
usb_serial
*
serial
;
struct
usb_serial_port
*
port
;
int
i
;
serial
=
to_usb_serial
(
kref
);
dbg
(
"%s - %s"
,
__FUNCTION__
,
serial
->
type
->
name
);
serial
->
type
->
shutdown
(
serial
);
/* return the minor range that this device had */
return_serial
(
serial
);
for
(
i
=
0
;
i
<
serial
->
num_ports
;
++
i
)
serial
->
port
[
i
]
->
open_count
=
0
;
/* the ports are cleaned up and released in port_release() */
for
(
i
=
0
;
i
<
serial
->
num_ports
;
++
i
)
if
(
serial
->
port
[
i
]
->
dev
.
parent
!=
NULL
)
{
device_unregister
(
&
serial
->
port
[
i
]
->
dev
);
serial
->
port
[
i
]
=
NULL
;
}
/* If this is a "fake" port, we have to clean it up here, as it will
* not get cleaned up in port_release() as it was never registered with
* the driver core */
if
(
serial
->
num_ports
<
serial
->
num_port_pointers
)
{
for
(
i
=
serial
->
num_ports
;
i
<
serial
->
num_port_pointers
;
++
i
)
{
port
=
serial
->
port
[
i
];
if
(
!
port
)
continue
;
if
(
port
->
read_urb
)
{
usb_unlink_urb
(
port
->
read_urb
);
usb_free_urb
(
port
->
read_urb
);
}
if
(
port
->
write_urb
)
{
usb_unlink_urb
(
port
->
write_urb
);
usb_free_urb
(
port
->
write_urb
);
}
if
(
port
->
interrupt_in_urb
)
{
usb_unlink_urb
(
port
->
interrupt_in_urb
);
usb_free_urb
(
port
->
interrupt_in_urb
);
}
kfree
(
port
->
bulk_in_buffer
);
kfree
(
port
->
bulk_out_buffer
);
kfree
(
port
->
interrupt_in_buffer
);
}
}
usb_put_dev
(
serial
->
dev
);
/* free up any memory that we allocated */
kfree
(
serial
);
}
/*****************************************************************************
/*****************************************************************************
* Driver tty interface functions
* Driver tty interface functions
*****************************************************************************/
*****************************************************************************/
...
@@ -465,7 +522,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
...
@@ -465,7 +522,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
if
(
retval
)
{
if
(
retval
)
{
port
->
open_count
=
0
;
port
->
open_count
=
0
;
module_put
(
serial
->
type
->
owner
);
module_put
(
serial
->
type
->
owner
);
kref_put
(
&
serial
->
kref
);
kref_put
(
&
serial
->
kref
,
destroy_serial
);
}
}
}
}
bailout:
bailout:
...
@@ -496,7 +553,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
...
@@ -496,7 +553,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
}
}
module_put
(
port
->
serial
->
type
->
owner
);
module_put
(
port
->
serial
->
type
->
owner
);
kref_put
(
&
port
->
serial
->
kref
);
kref_put
(
&
port
->
serial
->
kref
,
destroy_serial
);
}
}
static
int
serial_write
(
struct
tty_struct
*
tty
,
int
from_user
,
const
unsigned
char
*
buf
,
int
count
)
static
int
serial_write
(
struct
tty_struct
*
tty
,
int
from_user
,
const
unsigned
char
*
buf
,
int
count
)
...
@@ -654,13 +711,6 @@ static void serial_break (struct tty_struct *tty, int break_state)
...
@@ -654,13 +711,6 @@ static void serial_break (struct tty_struct *tty, int break_state)
;
;
}
}
static
void
serial_shutdown
(
struct
usb_serial
*
serial
)
{
dbg
(
"%s"
,
__FUNCTION__
);
serial
->
type
->
shutdown
(
serial
);
}
static
int
serial_read_proc
(
char
*
page
,
char
**
start
,
off_t
off
,
int
count
,
int
*
eof
,
void
*
data
)
static
int
serial_read_proc
(
char
*
page
,
char
**
start
,
off_t
off
,
int
count
,
int
*
eof
,
void
*
data
)
{
{
struct
usb_serial
*
serial
;
struct
usb_serial
*
serial
;
...
@@ -694,7 +744,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
...
@@ -694,7 +744,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
begin
+=
length
;
begin
+=
length
;
length
=
0
;
length
=
0
;
}
}
kref_put
(
&
serial
->
kref
);
kref_put
(
&
serial
->
kref
,
destroy_serial
);
}
}
*
eof
=
1
;
*
eof
=
1
;
done:
done:
...
@@ -763,62 +813,6 @@ void usb_serial_port_softint(void *private)
...
@@ -763,62 +813,6 @@ void usb_serial_port_softint(void *private)
wake_up_interruptible
(
&
tty
->
write_wait
);
wake_up_interruptible
(
&
tty
->
write_wait
);
}
}
static
void
destroy_serial
(
struct
kref
*
kref
)
{
struct
usb_serial
*
serial
;
struct
usb_serial_port
*
port
;
int
i
;
serial
=
to_usb_serial
(
kref
);
dbg
(
"%s - %s"
,
__FUNCTION__
,
serial
->
type
->
name
);
serial_shutdown
(
serial
);
/* return the minor range that this device had */
return_serial
(
serial
);
for
(
i
=
0
;
i
<
serial
->
num_ports
;
++
i
)
serial
->
port
[
i
]
->
open_count
=
0
;
/* the ports are cleaned up and released in port_release() */
for
(
i
=
0
;
i
<
serial
->
num_ports
;
++
i
)
if
(
serial
->
port
[
i
]
->
dev
.
parent
!=
NULL
)
{
device_unregister
(
&
serial
->
port
[
i
]
->
dev
);
serial
->
port
[
i
]
=
NULL
;
}
/* If this is a "fake" port, we have to clean it up here, as it will
* not get cleaned up in port_release() as it was never registered with
* the driver core */
if
(
serial
->
num_ports
<
serial
->
num_port_pointers
)
{
for
(
i
=
serial
->
num_ports
;
i
<
serial
->
num_port_pointers
;
++
i
)
{
port
=
serial
->
port
[
i
];
if
(
!
port
)
continue
;
if
(
port
->
read_urb
)
{
usb_unlink_urb
(
port
->
read_urb
);
usb_free_urb
(
port
->
read_urb
);
}
if
(
port
->
write_urb
)
{
usb_unlink_urb
(
port
->
write_urb
);
usb_free_urb
(
port
->
write_urb
);
}
if
(
port
->
interrupt_in_urb
)
{
usb_unlink_urb
(
port
->
interrupt_in_urb
);
usb_free_urb
(
port
->
interrupt_in_urb
);
}
kfree
(
port
->
bulk_in_buffer
);
kfree
(
port
->
bulk_out_buffer
);
kfree
(
port
->
interrupt_in_buffer
);
}
}
usb_put_dev
(
serial
->
dev
);
/* free up any memory that we allocated */
kfree
(
serial
);
}
static
void
port_release
(
struct
device
*
dev
)
static
void
port_release
(
struct
device
*
dev
)
{
{
struct
usb_serial_port
*
port
=
to_usb_serial_port
(
dev
);
struct
usb_serial_port
*
port
=
to_usb_serial_port
(
dev
);
...
@@ -859,7 +853,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
...
@@ -859,7 +853,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
serial
->
interface
=
interface
;
serial
->
interface
=
interface
;
serial
->
vendor
=
dev
->
descriptor
.
idVendor
;
serial
->
vendor
=
dev
->
descriptor
.
idVendor
;
serial
->
product
=
dev
->
descriptor
.
idProduct
;
serial
->
product
=
dev
->
descriptor
.
idProduct
;
kref_init
(
&
serial
->
kref
,
destroy_serial
);
kref_init
(
&
serial
->
kref
);
return
serial
;
return
serial
;
}
}
...
@@ -1209,7 +1203,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
...
@@ -1209,7 +1203,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
if
(
serial
)
{
if
(
serial
)
{
/* let the last holder of this object
/* let the last holder of this object
* cause it to be cleaned up */
* cause it to be cleaned up */
kref_put
(
&
serial
->
kref
);
kref_put
(
&
serial
->
kref
,
destroy_serial
);
}
}
dev_info
(
dev
,
"device disconnected
\n
"
);
dev_info
(
dev
,
"device disconnected
\n
"
);
}
}
...
...
include/linux/kref.h
View file @
95e07832
...
@@ -18,15 +18,12 @@
...
@@ -18,15 +18,12 @@
#include <linux/types.h>
#include <linux/types.h>
#include <asm/atomic.h>
#include <asm/atomic.h>
struct
kref
{
struct
kref
{
atomic_t
refcount
;
atomic_t
refcount
;
void
(
*
release
)(
struct
kref
*
kref
);
};
};
void
kref_init
(
struct
kref
*
kref
,
void
(
*
release
)(
struct
kref
*
)
);
void
kref_init
(
struct
kref
*
kref
);
struct
kref
*
kref_get
(
struct
kref
*
kref
);
struct
kref
*
kref_get
(
struct
kref
*
kref
);
void
kref_put
(
struct
kref
*
kref
);
void
kref_put
(
struct
kref
*
kref
,
void
(
*
release
)
(
struct
kref
*
kref
));
#endif
/* _KREF_H_ */
#endif
/* _KREF_H_ */
lib/kref.c
View file @
95e07832
...
@@ -11,23 +11,16 @@
...
@@ -11,23 +11,16 @@
*
*
*/
*/
/* #define DEBUG */
#include <linux/kref.h>
#include <linux/kref.h>
#include <linux/module.h>
#include <linux/module.h>
/**
/**
* kref_init - initialize object.
* kref_init - initialize object.
* @kref: object in question.
* @kref: object in question.
* @release: pointer to a function that will clean up the object
* when the last reference to the object is released.
* This pointer is required.
*/
*/
void
kref_init
(
struct
kref
*
kref
,
void
(
*
release
)(
struct
kref
*
kref
)
)
void
kref_init
(
struct
kref
*
kref
)
{
{
WARN_ON
(
release
==
NULL
);
atomic_set
(
&
kref
->
refcount
,
1
);
atomic_set
(
&
kref
->
refcount
,
1
);
kref
->
release
=
release
;
}
}
/**
/**
...
@@ -44,15 +37,20 @@ struct kref *kref_get(struct kref *kref)
...
@@ -44,15 +37,20 @@ struct kref *kref_get(struct kref *kref)
/**
/**
* kref_put - decrement refcount for object.
* kref_put - decrement refcount for object.
* @kref: object.
* @kref: object.
* @release: pointer to the function that will clean up the object when the
* last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree
* in as this function.
*
*
* Decrement the refcount, and if 0, call
kref->
release().
* Decrement the refcount, and if 0, call release().
*/
*/
void
kref_put
(
struct
kref
*
kref
)
void
kref_put
(
struct
kref
*
kref
,
void
(
*
release
)
(
struct
kref
*
kref
)
)
{
{
if
(
atomic_dec_and_test
(
&
kref
->
refcount
))
{
WARN_ON
(
release
==
NULL
);
pr_debug
(
"kref cleaning up
\n
"
);
WARN_ON
(
release
==
(
void
(
*
)(
struct
kref
*
))
kfree
);
kref
->
release
(
kref
);
}
if
(
atomic_dec_and_test
(
&
kref
->
refcount
))
release
(
kref
);
}
}
EXPORT_SYMBOL
(
kref_init
);
EXPORT_SYMBOL
(
kref_init
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment