···326326327327static int328328__ftrace_replace_code(struct dyn_ftrace *rec,329329- unsigned char *old, unsigned char *new, int enable)329329+ unsigned char *nop, int enable)330330{331331 unsigned long ip, fl;332332+ unsigned char *call, *old, *new;332333333334 ip = rec->ip;334335335335- if (ftrace_filtered && enable) {336336- /*337337- * If filtering is on:338338- *339339- * If this record is set to be filtered and340340- * is enabled then do nothing.341341- *342342- * If this record is set to be filtered and343343- * it is not enabled, enable it.344344- *345345- * If this record is not set to be filtered346346- * and it is not enabled do nothing.347347- *348348- * If this record is set not to trace then349349- * do nothing.350350- *351351- * If this record is set not to trace and352352- * it is enabled then disable it.353353- *354354- * If this record is not set to be filtered and355355- * it is enabled, disable it.356356- */357357-358358- fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |359359- FTRACE_FL_ENABLED);360360-361361- if ((fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||362362- (fl == (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||363363- !fl || (fl == FTRACE_FL_NOTRACE))336336+ /*337337+ * If this record is not to be traced and338338+ * it is not enabled then do nothing.339339+ *340340+ * If this record is not to be traced and341341+ * it is enabled then disabled it.342342+ *343343+ */344344+ if (rec->flags & FTRACE_FL_NOTRACE) {345345+ if (rec->flags & FTRACE_FL_ENABLED)346346+ rec->flags &= ~FTRACE_FL_ENABLED;347347+ else364348 return 0;365349350350+ } else if (ftrace_filtered && enable) {366351 /*367367- * If it is enabled disable it,368368- * otherwise enable it!352352+ * Filtering is on:369353 */370370- if (fl & FTRACE_FL_ENABLED) {371371- /* swap new and old */372372- new = old;373373- old = ftrace_call_replace(ip, FTRACE_ADDR);354354+355355+ fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);356356+357357+ /* Record is filtered and enabled, do nothing */358358+ if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED))359359+ return 0;360360+361361+ /* Record is not filtered and is not enabled do nothing */362362+ if (!fl)363363+ return 0;364364+365365+ /* Record is not filtered but enabled, disable it */366366+ if (fl == FTRACE_FL_ENABLED)374367 rec->flags &= ~FTRACE_FL_ENABLED;375375- } else {376376- new = ftrace_call_replace(ip, FTRACE_ADDR);368368+ else369369+ /* Otherwise record is filtered but not enabled, enable it */377370 rec->flags |= FTRACE_FL_ENABLED;378378- }379371 } else {372372+ /* Disable or not filtered */380373381374 if (enable) {382382- /*383383- * If this record is set not to trace and is384384- * not enabled, do nothing.385385- */386386- fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);387387- if (fl == FTRACE_FL_NOTRACE)388388- return 0;389389-390390- new = ftrace_call_replace(ip, FTRACE_ADDR);391391- } else392392- old = ftrace_call_replace(ip, FTRACE_ADDR);393393-394394- if (enable) {375375+ /* if record is enabled, do nothing */395376 if (rec->flags & FTRACE_FL_ENABLED)396377 return 0;378378+397379 rec->flags |= FTRACE_FL_ENABLED;380380+398381 } else {382382+383383+ /* if record is not enabled do nothing */399384 if (!(rec->flags & FTRACE_FL_ENABLED))400385 return 0;386386+401387 rec->flags &= ~FTRACE_FL_ENABLED;402388 }389389+ }390390+391391+ call = ftrace_call_replace(ip, FTRACE_ADDR);392392+393393+ if (rec->flags & FTRACE_FL_ENABLED) {394394+ old = nop;395395+ new = call;396396+ } else {397397+ old = call;398398+ new = nop;403399 }404400405401 return ftrace_modify_code(ip, old, new);···404408static void ftrace_replace_code(int enable)405409{406410 int i, failed;407407- unsigned char *new = NULL, *old = NULL;411411+ unsigned char *nop = NULL;408412 struct dyn_ftrace *rec;409413 struct ftrace_page *pg;410414411411- if (enable)412412- old = ftrace_nop_replace();413413- else414414- new = ftrace_nop_replace();415415+ nop = ftrace_nop_replace();415416416417 for (pg = ftrace_pages_start; pg; pg = pg->next) {417418 for (i = 0; i < pg->index; i++) {···426433 unfreeze_record(rec);427434 }428435429429- failed = __ftrace_replace_code(rec, old, new, enable);436436+ failed = __ftrace_replace_code(rec, nop, enable);430437 if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {431438 rec->flags |= FTRACE_FL_FAILED;432439 if ((system_state == SYSTEM_BOOTING) ||···527534528535 mutex_lock(&ftrace_start_lock);529536 ftrace_start++;530530- if (ftrace_start == 1)531531- command |= FTRACE_ENABLE_CALLS;537537+ command |= FTRACE_ENABLE_CALLS;532538533539 if (saved_ftrace_func != ftrace_trace_function) {534540 saved_ftrace_func = ftrace_trace_function;···725733726734 ((iter->flags & FTRACE_ITER_FAILURES) &&727735 !(rec->flags & FTRACE_FL_FAILED)) ||736736+737737+ ((iter->flags & FTRACE_ITER_FILTER) &&738738+ !(rec->flags & FTRACE_FL_FILTER)) ||728739729740 ((iter->flags & FTRACE_ITER_NOTRACE) &&730741 !(rec->flags & FTRACE_FL_NOTRACE))) {···1181118611821187 mutex_lock(&ftrace_sysctl_lock);11831188 mutex_lock(&ftrace_start_lock);11841184- if (iter->filtered && ftrace_start && ftrace_enabled)11891189+ if (ftrace_start && ftrace_enabled)11851190 ftrace_run_update_code(FTRACE_ENABLE_CALLS);11861191 mutex_unlock(&ftrace_start_lock);11871192 mutex_unlock(&ftrace_sysctl_lock);