yaoxinjing/simpleDeviceDriver

Code repetition

Closed this issue · 1 comments

These lines

xa_lock_bh(&key_value_store);
err = xa_err(__xa_store(&key_value_store, next_index, p, GFP_KERNEL));
if (!err) {
next_index++;
xa_unlock_bh(&key_value_store);
return key;
}
xa_unlock_bh(&key_value_store);

And these lines

// storie a new entry in the key value store
if (index<0) {
xa_lock_bh(&key_value_store);
err = xa_err(__xa_store(&key_value_store, next_index, pair, GFP_KERNEL));
if (!err)
next_index++;
xa_unlock_bh(&key_value_store);
return err; //A negative errno or 0
}
//change the already exist key-value in the store

Repeat almost verbatim, except a small difference.

Repeating the code, instead of reusing is extremely bug-prone. Avoid it as much as possible.

Moreover. Why don't you use normal xa_store?

thanks, i deleted this func, and use xa_store to save the entry in xarray