Skip to content

Commit a04ee14

Browse files
Jan EngelhardtLinus Torvalds
authored andcommitted
[PATCH] openpromfs: factorize out
"Move" "common code" out to PTR_NOD, which does the conversion from private pointer to node number. This is to reduce potential casting/conversion errors due to redundancy. (The naming PTR_NOD follows PTR_ERR, turning a pointer into xyz.) [akpm@osdl.org: cleanups] Signed-off-by: Jan Engelhardt <jengelh@gmx.de> Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 515decd commit a04ee14

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎fs/openpromfs/inode.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ static int openpromfs_readdir(struct file *, void *, filldir_t);
6464
static struct dentry *openpromfs_lookup(struct inode *, struct dentry *dentry, struct nameidata *nd);
6565
static int openpromfs_unlink (struct inode *, struct dentry *dentry);
6666

67+
static inline u16 ptr_nod(void *p)
68+
{
69+
return (long)p & 0xFFFF;
70+
}
71+
6772
static ssize_t nodenum_read(struct file *file, char __user *buf,
6873
size_t count, loff_t *ppos)
6974
{
@@ -95,9 +100,9 @@ static ssize_t property_read(struct file *filp, char __user *buf,
95100
char buffer[64];
96101

97102
if (!filp->private_data) {
98-
node = nodes[(u16)((long)inode->u.generic_ip)].node;
103+
node = nodes[ptr_nod(inode->u.generic_ip)].node;
99104
i = ((u32)(long)inode->u.generic_ip) >> 16;
100-
if ((u16)((long)inode->u.generic_ip) == aliases) {
105+
if (ptr_nod(inode->u.generic_ip) == aliases) {
101106
if (i >= aliases_nodes)
102107
p = NULL;
103108
else
@@ -111,7 +116,7 @@ static ssize_t property_read(struct file *filp, char __user *buf,
111116
return -EIO;
112117
i = prom_getproplen (node, p);
113118
if (i < 0) {
114-
if ((u16)((long)inode->u.generic_ip) == aliases)
119+
if (ptr_nod(inode->u.generic_ip) == aliases)
115120
i = 0;
116121
else
117122
return -EIO;
@@ -540,8 +545,8 @@ int property_release (struct inode *inode, struct file *filp)
540545
if (!op)
541546
return 0;
542547
lock_kernel();
543-
node = nodes[(u16)((long)inode->u.generic_ip)].node;
544-
if ((u16)((long)inode->u.generic_ip) == aliases) {
548+
node = nodes[ptr_nod(inode->u.generic_ip)].node;
549+
if (ptr_nod(inode->u.generic_ip) == aliases) {
545550
if ((op->flag & OPP_DIRTY) && (op->flag & OPP_STRING)) {
546551
char *p = op->name;
547552
int i = (op->value - op->name) - strlen (op->name) - 1;

0 commit comments

Comments
 (0)