* [PATCH] btrfs: Use list_last_entry in add_falloc_range
@ 2021-05-31 7:37 Nikolay Borisov
2021-05-31 18:45 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Borisov @ 2021-05-31 7:37 UTC (permalink / raw)
To: linux-btrfs; +Cc: Nikolay Borisov
Instead of calling list_entry with head->prev simply call
list_last_entry which makes it obvious which member of the list is
being referred. This allows to remove the extra 'prev' pointer.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/file.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e910cc2cd45c..2b28a3daa5a9 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3034,7 +3034,6 @@ struct falloc_range {
*/
static int add_falloc_range(struct list_head *head, u64 start, u64 len)
{
- struct falloc_range *prev = NULL;
struct falloc_range *range = NULL;
if (list_empty(head))
@@ -3044,9 +3043,9 @@ static int add_falloc_range(struct list_head *head, u64 start, u64 len)
* As fallocate iterate by bytenr order, we only need to check
* the last range.
*/
- prev = list_entry(head->prev, struct falloc_range, list);
- if (prev->start + prev->len == start) {
- prev->len += len;
+ range = list_last_entry(head, struct falloc_range, list);
+ if (range->start + range->len == start) {
+ range->len += len;
return 0;
}
insert:
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: Use list_last_entry in add_falloc_range
2021-05-31 7:37 [PATCH] btrfs: Use list_last_entry in add_falloc_range Nikolay Borisov
@ 2021-05-31 18:45 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-05-31 18:45 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: linux-btrfs
On Mon, May 31, 2021 at 10:37:03AM +0300, Nikolay Borisov wrote:
> Instead of calling list_entry with head->prev simply call
> list_last_entry which makes it obvious which member of the list is
> being referred. This allows to remove the extra 'prev' pointer.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Added to misc-next, thanks.
> ---
> fs/btrfs/file.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e910cc2cd45c..2b28a3daa5a9 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -3034,7 +3034,6 @@ struct falloc_range {
> */
> static int add_falloc_range(struct list_head *head, u64 start, u64 len)
> {
> - struct falloc_range *prev = NULL;
> struct falloc_range *range = NULL;
>
> if (list_empty(head))
> @@ -3044,9 +3043,9 @@ static int add_falloc_range(struct list_head *head, u64 start, u64 len)
> * As fallocate iterate by bytenr order, we only need to check
> * the last range.
> */
> - prev = list_entry(head->prev, struct falloc_range, list);
> - if (prev->start + prev->len == start) {
> - prev->len += len;
> + range = list_last_entry(head, struct falloc_range, list);
> + if (range->start + range->len == start) {
> + range->len += len;
> return 0;
> }
> insert:
The function could be restructured a bit to get rid of the insert:
label, like:
if (!list_empty(head)) {
range = list_last(...)
if (range->start ...) {
return;
}
}
range = kmalloc(...)
<the rest>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-31 18:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31 7:37 [PATCH] btrfs: Use list_last_entry in add_falloc_range Nikolay Borisov
2021-05-31 18:45 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.